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? Quote Link to comment 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 Quote Link to comment 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"; Quote Link to comment Share on other sites More sharing options...
tail Posted June 3, 2007 Share Posted June 3, 2007 could also be done with mktime Quote Link to comment 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 Quote Link to comment 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 />"; ?> Quote Link to comment Share on other sites More sharing options...
AXiSS Posted June 5, 2007 Author Share Posted June 5, 2007 Cool, that worked. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.