DBookatay Posted July 3, 2009 Share Posted July 3, 2009 I have a cell in my dB named 'pur_date' with the "date" value: 2009-07-03. How do I count the number of days (based on todays date) that it's been in inventory? Link to comment https://forums.phpfreaks.com/topic/164691-solved-help-counting-the-number-of-days-in-inventory/ Share on other sites More sharing options...
sasa Posted July 3, 2009 Share Posted July 3, 2009 look datediff() mysql function Link to comment https://forums.phpfreaks.com/topic/164691-solved-help-counting-the-number-of-days-in-inventory/#findComment-868473 Share on other sites More sharing options...
DBookatay Posted July 3, 2009 Author Share Posted July 3, 2009 look datediff() mysql function I'm obviously doing something wrong cause this is not returning the right number of days... // Days in inventory $date1 = date("Y").'-'.date(d).'-'.date("m"); $date2 = $row['pur_date']; $diff = abs(strtotime($date2) - strtotime($date1)); $years = floor($diff / (365*60*60*24)); $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24)); $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24)); if ($years !="0") {$years = $years.' yrs, ';} else {$years = NULL;} if ($months !="0") {$months = $months.' mnths, ';} else {$months = NULL;} $daysIn = $years.$months.$days.' days'; Link to comment https://forums.phpfreaks.com/topic/164691-solved-help-counting-the-number-of-days-in-inventory/#findComment-868574 Share on other sites More sharing options...
DBookatay Posted July 4, 2009 Author Share Posted July 4, 2009 Anyone have any suggestions? Link to comment https://forums.phpfreaks.com/topic/164691-solved-help-counting-the-number-of-days-in-inventory/#findComment-868788 Share on other sites More sharing options...
DBookatay Posted July 4, 2009 Author Share Posted July 4, 2009 Anyone have any suggestions? I solved it myself... $date1 = date("Y").'-'.date(d).'-'.date("m"); ----- should be ----- $date1 = date("Y").'-'.date(m).'-'.date("d"); Link to comment https://forums.phpfreaks.com/topic/164691-solved-help-counting-the-number-of-days-in-inventory/#findComment-868853 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.