Page 1 of 1

Days since date

Posted: Thu Jul 01, 2010 11:33 am
by hauni
Alright, I have 2 dates.
They first is written like this:
02/03/04
and the second is todays' date:
01/07/10.

Now I wonder, can anyone help me with a script that calculates how many days it has gone (days, not months or weeks) since the first date to the second?
I would be so grateful.
Thanks.

Re: Days since date

Posted: Thu Jul 01, 2010 11:37 am
by mikosiko

Re: Days since date

Posted: Thu Jul 01, 2010 11:41 am
by hauni
i want to do it in php, not sql.
Thanks for quick answer.

Re: Days since date

Posted: Thu Jul 01, 2010 12:50 pm
by AbraCadaver
Those dates won't be handled correctly by strtotime(), so something like this:

Code: Select all

$start = explode('/', '02/03/04');
$end = explode('/', '01/07/10');
$days = (mktime(0,0,0,$end[1],$end[0],$end[2]) - mktime(0,0,0,$start[1],$start[0],$start[2])) / 86400; //60sec * 60min * 24hrs 
You can use abs() on the result if the start date can be greater than the end date. Also, you can use round(), ceil() or floor() to round the days as appropriate.