Jump to content

How to Compare dates?


ballhogjoni

Recommended Posts

1. Read the manual.

2. Your comparison is backwards.

 

Assuming that 2008 date is just an example,

if ("2008-08-10 00:00:00" 

 

Note that it takes the current time into account too. If today was 2008-08-10 and it was one second past midnight, the condition would pass.

Learn to love the date function and strtotime()...

 

 

Any time string like you have 2008-08-10 00:00:00, or 10/08/2010 or 02-12-10 5:00:00 pm.... will have to be ran through strtotime before making any comparison operations.

 

I could be wrong, but I don't think requinix's example will work. I am not sure that you can compare a date in that format. I could be wrong, so try it and see.. if it does not work, then try this one...

 

if (strtotime("2008-08-10 00:00:00") < strtotime("now") ) {......

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.