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? Quote 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 Quote 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'; Quote 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? Quote 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"); Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.