SA-MP Forums Archive
How to check for "Some Date" older than "Current Date"? - 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: How to check for "Some Date" older than "Current Date"? (/showthread.php?tid=327751)



How to check for "Some Date" older than "Current Date"? - iPLEOMAX - 22.03.2012

Like for example, I have a date: "13th March 2011, 22:34.5" and today's date is "22 March 2012 3:17.16"

How can I compare the dates and check whether the date is older or newer?


Re: How to check for "Some Date" older than "Current Date"? - Roel - 22.03.2012

Well best thing you can do is: use getdate(); for this.
So you save for example:
Код:
new date1;
date1 = getdate();
and next week you check
Код:
new date2;
date2 = getdate();
if(date2 > date1) //then is date1 older .
Moreinfo:
https://sampwiki.blast.hk/wiki/Getdate


Re: How to check for "Some Date" older than "Current Date"? - Babul - 22.03.2012

compare each value in a decreasing order: year, month, day, hour, minute, second. when any comparison returns a difference, the date is (depends on how you check it, > or <) bigger.
are all date strings formatted the same way? yours looks like
pawn Код:
format(datestring,sizeof(datestring),"%dth %s %d, %d:%d,%d",day,monthname[month],year,hour,minute,second);
so by using
pawn Код:
sscanf(datestring,"d' 's[16]' 'd','d':'d'.'d",day,month,year,hour,minute,second)
and reordering the comparisons (years before months), it should work


Re: How to check for "Some Date" older than "Current Date"? - Roel - 22.03.2012

Quote:
Originally Posted by Babul
Посмотреть сообщение
compare each value in a decreasing order: year, month, day, hour, minute, second. when any comparison returns a difference, the date is different. are all date strings formatted the same way? yours looks like
pawn Код:
format(datestring,sizeof(datestring),"%dth %s %d, %d:%d,%d",day,monthname[month],year,hour,minute,second);
so by using
pawn Код:
sscanf(datestring,"d' 's[16]' 'd','d':'d'.'d",day,month,year,hour,minute,second)
and reordering the comparisons (years before months), it should work
Thats also possible, but it's much more work then the way I explain. But yea if you wan't you can use babul's way.


Re: How to check for "Some Date" older than "Current Date"? - Babul - 22.03.2012

one issue using my method, is the need of converting the month string into a number ("march"=3) for easier comparing, which is not that easy for strings. if all date informations are stored as numerical values, its a piece of cake


Re: How to check for "Some Date" older than "Current Date"? - Roel - 22.03.2012

Yep, but you can store all date informations in numerical right?
Only if a player has to input the date by hisself you cannot use my option.
Anyway we will see what he uses :P


Re: How to check for "Some Date" older than "Current Date"? - CyNiC - 22.03.2012

mktime: Get the timestamp from date.

getdate: Get the actual timestamp

Due to timezone, maybe is need to decrease/increase the mktime timestamp in some hours.


Re: How to check for "Some Date" older than "Current Date"? - Basssiiie - 22.03.2012

Be aware that on the 31th of December 'getdate()' returns something like 365, but on the 1st of January, it returns 0 or 1 again. So it's safe, as long as the dates aren't around New Year. Maybe it's useful to compare the years too.


Re: How to check for "Some Date" older than "Current Date"? - Calgon - 22.03.2012

I made a fairly decent guide explaining Unix Timestamps a while ago, this might not be what you want, but this is the most effective way of dealing with dates.


Re: How to check for "Some Date" older than "Current Date"? - iPLEOMAX - 22.03.2012

Thanks everyone, all your information were useful. I've overcome this problem.