jeff5656 Posted November 9, 2008 Share Posted November 9, 2008 Whats the code to compare to see if the current date is more than 24 hours old? would this work? (I didn't include the $query database lines): $curr_date = date ("Y-m-d"); $today = strtotime ($curr_date); if ($row['problist_date'] <= $curr_date ....???? { echo "the entry was last edited more than 24 hours ago" } else { echo "entry is up to date"; } Link to comment https://forums.phpfreaks.com/topic/131978-date-compare/ Share on other sites More sharing options...
ratcateme Posted November 9, 2008 Share Posted November 9, 2008 what format is problist_date in? a unix timestamp or a formatted date for a foramtted date try this if((strtotime($row['problist_date'])+24*60*60) < time()){ echo "the entry was last edited more than 24 hours ago" }else{ echo "entry is up to date"; }[code=php:0] and for a unix timestamp use [code=php:0]if(($row['problist_date'+24]*60*60) < time()){ by unix timestamp i mean seconds past January 1, 1970 Scott. Link to comment https://forums.phpfreaks.com/topic/131978-date-compare/#findComment-685773 Share on other sites More sharing options...
jeff5656 Posted November 9, 2008 Author Share Posted November 9, 2008 Yes it is a DATE format. Actually, what happens if the entry is 0000-00-00? I don't want that to count as being more than 24 hours ago. What do I do about those fields? Link to comment https://forums.phpfreaks.com/topic/131978-date-compare/#findComment-685776 Share on other sites More sharing options...
ratcateme Posted November 9, 2008 Share Posted November 9, 2008 i would recommend making it a DATETIME field as if you put in a time at say 2008-11-09 23:59 that would be recorded as 2008-11-09 with is fine but by 2008-11-10 00:01 that code would say it is older than 24 hours even though it has only been 2 mins a DATETIME field would solve that Scott. Link to comment https://forums.phpfreaks.com/topic/131978-date-compare/#findComment-685789 Share on other sites More sharing options...
jeff5656 Posted November 9, 2008 Author Share Posted November 9, 2008 I changed the field from DATE to DATETIME, so how do I update this: $current_date = date ("m/d/y"); $problist_date = date("Y-m-d", strtotime($current_date)); Also, how do I deal with fields that don't have an entry yet and therefor are "0000-00-00" in the database? tnx Link to comment https://forums.phpfreaks.com/topic/131978-date-compare/#findComment-685792 Share on other sites More sharing options...
ratcateme Posted November 9, 2008 Share Posted November 9, 2008 $problist_date = date("Y-m-d H:i:s"); $current_date = date ("m/d/y"); with the old entries i guess mysql has made them all yyyy-mm-dd 00:00:00 and so your current display does not show the hour:mins:secs? so it should be all good Scott. Link to comment https://forums.phpfreaks.com/topic/131978-date-compare/#findComment-685793 Share on other sites More sharing options...
Stooney Posted November 9, 2008 Share Posted November 9, 2008 <?php //Current timestamp $today=mktime(); //Current timestamp minus 24 hours $hours24=mktime(date("s"), date("i"), date("H"), date("m"), date("d")-1, date("Y")); //Timestamp of the date you're comparing $compare='TIMESTAMP HERE'; //If $today is less that $compare, 24 hours has passed. if($hours24<$compare && $today>$compare){ echo "24 Hours has passed"; } else if($today>$compare){ echo "The date you are comparing is in the future from now"; } else{ echo "24 Hours has not passed"; } ?> Link to comment https://forums.phpfreaks.com/topic/131978-date-compare/#findComment-685794 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.