SA-MP Forums Archive
Date to integers? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Date to integers? (/showthread.php?tid=355950)



Date to integers? - Ranama - 01.07.2012

Hello!
I'm making my ban command and auto detecting if they are unbanned date.
so I wonder how to get a date such as '2012-02-23' into integers year = 2012, month = 2, day = 23
I've got an idea on strcmp to compare if there are any numbers inside there wich is a date and in some way convert them to integers, but this shoud take some work as i would need to check for every single number that can be in there.
So is there any way to get this to work?
The compare thing i use is i get the date and for every year i * 365, month*30 and then add it all together with the day and i should do this with the mysql saved date to.

Or is there any function to compare 2 dates?

Sorry if you don't understand, just ask and I'll try to explain.

I'm thankfull for every answer i get


Re: Date to integers? - Vince - 01.07.2012

Unix timestamps.


Re: Date to integers? - pyrodave - 01.07.2012

To split the dates as you have up, you could use sscanf:
pawn Код:
new year,month,day;
sscanf("2012-02-23","p<->ddd",year,month,day);
printf("Year: %d Month: %d Day: %d",year,month,day);
//Prints "Year: 2012 Month: 2 Day: 23"



Re: Date to integers? - Ranama - 01.07.2012

Quote:
Originally Posted by pyrodave
Посмотреть сообщение
To split the dates as you have up, you could use sscanf:
pawn Код:
new year,month,day;
sscanf("2012-02-23","p<->ddd",year,month,day);
printf("Year: %d Month: %d Day: %d",year,month,day);
//Prints "Year: 2012 Month: 2 Day: 23"
Oh, thank you will try that thanks for the fast and easy answer ^^


Re: Date to integers? - cessil - 02.07.2012

as vince said, unix time stamps, they would be a lot easier to use since you don't have to worry about days in months ect. it's just one number that increases over time


Re: Date to integers? - CaptainMactavish - 02.07.2012

Quote:
Originally Posted by Vince
Посмотреть сообщение
Unix timestamps.
Quote:
Originally Posted by cessil
Посмотреть сообщение
as vince said, unix time stamps, they would be a lot easier to use since you don't have to worry about days in months ect. it's just one number that increases over time
Yes, as they said, you can control that time in seconds, unix timestamps is just the seconds passed since 1st January of 1970.


Re: Date to integers? - AndreT - 02.07.2012

Sir, there are some functions in the CTime library that will become useful to you. From formatting time strings (for example in format "2012-12-31" that you have mentioned) to getting timestamp diffs - this plugin has the functionality. And it is not very difficulty to use, so I very much suggest trying it out. I hope there's nothing wrong with promoting the libraries that people have created.

Good luck scripting!