Page 1 of 1

comparing dates for past and present pages

Posted: Sun Dec 19, 2004 10:29 am
by andylyon87
Hey guys

I want to produce a page that has past and future gigs.

I want the user to add the gig and this is then added to a file, all the info is entered into a file including the date of the gig.

I was wondering whether I could compare the date in the file with the current date. Also how would I do that. Is it something like this (as an example).

Code: Select all

if($date<=date();)&#123;
print in future gig
&#125;else&#123;
print in past gigs
&#125;
Thanks in advance for any help

Posted: Sun Dec 19, 2004 11:06 am
by raging radish
Use time() to get the current timestamp and compare it to a future/past timestamp. Remember that the server may be in a different timezone as well.

Posted: Mon Dec 20, 2004 4:37 am
by andylyon87
I thought about that but the gigs will be future gigs is there anywhere where I can convert dates into a time().

Otherwise you would have to insert the date as time();

Posted: Mon Dec 20, 2004 12:11 pm
by raging radish
I think you can use strtotime() to take user input and convert it to a Unix timestamp. After that, comparison to a timestamp returned by time() should be easy.

http://ca3.php.net/manual/en/function.strtotime.php

Posted: Tue Dec 21, 2004 8:42 am
by andylyon87
I used mktime(!blah!); and then compared it to the current time(); and it has worked a treat thanks for the tips guys.