shocker-z Posted August 29, 2006 Share Posted August 29, 2006 how do i use date() funtione to calculate how many days ago the input date was? i tryed just calculatin it but YYYYMMDD but fell into issue of last month being 100+ days ago because it is 20060728 do i use ticks instead or is there a better function that's all singing and dancing? Quote Link to comment Share on other sites More sharing options...
obsidian Posted August 29, 2006 Share Posted August 29, 2006 how are you trying to calculate it? a typical, readable date format is YYYY-MM-DD with the dashes. however, for it to be readable by the date() function, you've got to change it to a timestamp with strtotime() or something similar. basically, here's a good way to calculate it:[code]<?php$date = "2006-04-01"; // april 1st of this year$today = date('Y-m-d');$diff = abs(strtotime($today) - strtotime($date));$days = ceil($diff / (60 * 60 * 24));echo "$days Days since date provided.";?>[/code]hope this helps. Quote Link to comment Share on other sites More sharing options...
Orio Posted August 29, 2006 Share Posted August 29, 2006 Use [url=http://www.php.net/manual/en/function.mktime.php]mktime()[/url] (IE mktime(0,0,0,month,day,year);) to create a time stamp for the old date.Then decrease from time() the result you get, devide by 60*60*24, and round it using [url=http://www.php.net/manual/en/function.floor.php]floor()[/url] or [url=http://www.php.net/manual/en/function.ceil.php]ceil()[/url].Orio. Quote Link to comment Share on other sites More sharing options...
shocker-z Posted August 29, 2006 Author Share Posted August 29, 2006 cheers obsidian that's working a treat! :D 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.