<?php
$thesetdate = $olddate;
$newdate = date("mdygis");
if ($thesetdate<$newdate){
do something
}
?>
comparing dates (PHP)
Started by Hip Hop Artist, Sep 03 2007 05:25 PM
3 replies to this topic
#1
Posted 03 September 2007 - 05:25 PM
i am using the date format date("mdygis"), and that gets stored in a database. I need to know if it would work if i did something like:
#2
Posted 03 September 2007 - 05:35 PM
No i don't think that will work. Date() creates a string representation of the date/time.
You want to compare the time(); based output wich is in seconds. (The amount of seconds since the linux epoch I think)
If you still want to use date() to get another timestamp (e.g. date("H:i:s",time()+3600) ) you could do the following:
strtotime(date("H:i:s",$timestamp))
but that's a bit off-topic. Conclusion:
Compare timestamps, not strings
You want to compare the time(); based output wich is in seconds. (The amount of seconds since the linux epoch I think)
If you still want to use date() to get another timestamp (e.g. date("H:i:s",time()+3600) ) you could do the following:
strtotime(date("H:i:s",$timestamp))
but that's a bit off-topic. Conclusion:
Compare timestamps, not strings
Edited by dotbart, 03 September 2007 - 05:36 PM.
#3
Posted 03 September 2007 - 05:41 PM
put how will i know if im comparing on the same date?
#4
Posted 03 September 2007 - 06:03 PM
That would work how you have it. Might not give you the results you want all the time, but it will work.
I recommend using time() though. 100% accurate 100% of the time.
I recommend using time() though. 100% accurate 100% of the time.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
