AXiSS Posted June 3, 2007 Share Posted June 3, 2007 Hello, I need to calculate the numbers of days (only the number of days) between two days, one a variable $row['user_cp_name'] in the format MM/DD/YY, and another, the current time. I've tried a bunch of tutorials on the internet and none seem to work properly. Can I get some help? Link to comment https://forums.phpfreaks.com/topic/54055-solved-calculating-days-between-two-dates/ Share on other sites More sharing options...
dough boy Posted June 3, 2007 Share Posted June 3, 2007 I am assuming that you are using values from MySQL. If so, use the DATEDIFF() function. http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_datediff Link to comment https://forums.phpfreaks.com/topic/54055-solved-calculating-days-between-two-dates/#findComment-267231 Share on other sites More sharing options...
dbillings Posted June 3, 2007 Share Posted June 3, 2007 if you don't have luck with that try $chunk= $row['user_cp_name']; $splice= explode("/", $chunk); $date= gmmktime(0,0,0,$splice[0],$splice[1],$splice[2],0); $diff= floor(time() - $date / 86400); echo "Days since $chunk: $diff"; Link to comment https://forums.phpfreaks.com/topic/54055-solved-calculating-days-between-two-dates/#findComment-267310 Share on other sites More sharing options...
tail Posted June 3, 2007 Share Posted June 3, 2007 could also be done with mktime Link to comment https://forums.phpfreaks.com/topic/54055-solved-calculating-days-between-two-dates/#findComment-267317 Share on other sites More sharing options...
AXiSS Posted June 5, 2007 Author Share Posted June 5, 2007 if you don't have luck with that try $chunk= $row['user_cp_name']; $splice= explode("/", $chunk); $date= gmmktime(0,0,0,$splice[0],$splice[1],$splice[2],0); $diff= floor(time() - $date / 86400); echo "Days since $chunk: $diff"; That gives me a number like: 1181002474 Link to comment https://forums.phpfreaks.com/topic/54055-solved-calculating-days-between-two-dates/#findComment-267968 Share on other sites More sharing options...
dbillings Posted June 5, 2007 Share Posted June 5, 2007 My bad I forgot to set the order for the math using brackets. Here you go. <?php $chunk= $row['user_cp_name']; $splice= explode("/", $chunk); $date= gmmktime(0,0,0,$splice[0],$splice[1],$splice[2],0); $diff= floor((time() - $date) / 86400); echo "Days since $chunk: $diff<br />"; ?> Link to comment https://forums.phpfreaks.com/topic/54055-solved-calculating-days-between-two-dates/#findComment-267979 Share on other sites More sharing options...
AXiSS Posted June 5, 2007 Author Share Posted June 5, 2007 Cool, that worked. Thanks! Link to comment https://forums.phpfreaks.com/topic/54055-solved-calculating-days-between-two-dates/#findComment-268010 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.