bhavin_85 Posted April 16, 2007 Share Posted April 16, 2007 hey guys ive had a little search but couldnt find anything i need to do the following calculation: if the date of the last order is less then 3 months ago from todays date return true else return false i know i need an if statement, but how do u do the actualy calculation? Quote Link to comment https://forums.phpfreaks.com/topic/47252-solved-date-calclation/ Share on other sites More sharing options...
kenrbnsn Posted April 16, 2007 Share Posted April 16, 2007 Use the strtotime() function to get the date of three months ago in a UNIX time stamp and the order date in a UNIX time stamp and then compare the two. <?php $order_date = strtotime('2007-03-14'); $three_months_ago = strtotime('-3 months'); if ($order_date < $three_months_ago) { // // old // } else { // // new // } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/47252-solved-date-calclation/#findComment-230440 Share on other sites More sharing options...
bhavin_85 Posted April 16, 2007 Author Share Posted April 16, 2007 ken....ive used this $threemonthdate = strtotime('-3 months'); and it is echoing this....1168965118 shouldnt it be in the date format - yyyy-mm-dd ??? Quote Link to comment https://forums.phpfreaks.com/topic/47252-solved-date-calclation/#findComment-230464 Share on other sites More sharing options...
kenrbnsn Posted April 16, 2007 Share Posted April 16, 2007 No, the strtotime() function returns a UNIX timestamp, i.e. the number of seconds since 1970-01-01. If you want to display it as a date string use <?php echo date('Y-m-d',$threemonthdate); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/47252-solved-date-calclation/#findComment-230478 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.