comparing dates for past and present pages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

comparing dates for past and present pages

Post 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
raging radish
Forum Commoner
Posts: 32
Joined: Sun Nov 14, 2004 3:02 pm
Location: Toronto

Post 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.
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

Post 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();
raging radish
Forum Commoner
Posts: 32
Joined: Sun Nov 14, 2004 3:02 pm
Location: Toronto

Post 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
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

Post 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.
Post Reply