Jump to content


comparing dates (PHP)


3 replies to this topic

#1 Hip Hop Artist

    Young Padawan

  • Members
  • Pip
  • 152 posts
  • Gender:Male
  • Location:Canada

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:

<?php
$thesetdate = $olddate;
$newdate = date("mdygis");

if ($thesetdate<$newdate){
do something
}
?>


#2 dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

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

Edited by dotbart, 03 September 2007 - 05:36 PM.


#3 Hip Hop Artist

    Young Padawan

  • Members
  • Pip
  • 152 posts
  • Gender:Male
  • Location:Canada

Posted 03 September 2007 - 05:41 PM

put how will i know if im comparing on the same date?

#4 pirateXcore

    Young Padawan

  • Members
  • Pip
  • 281 posts
  • Gender:Male

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users