views:

68

answers:

1

On one project, I have an internal calculation of times.

The days since the launch are simply enumerated:

2009/10/19: launch day 2009/10/20: day 1 2009/10/21: day 2 etc.

Now I would like to have a function which gives me the current day of the internal calculation of times. E.g. "day 129" on one day in 2010.

But it is important to have this accuracy:

2009/10/20 00:00:01 => day 1 2009/10/20 23:59:59 => day 1 2009/10/21 00:00:01 => day 2

I built the following function but it doesn't have that accuracy. Why not? Can you improve it?

function date2daycount($timestamp) {
 $launchDay = 1255903200-3600*24; // launch (2009/10/19 00:00:00)
 $difference = floor(($timestamp-$launchDay)/86400); // days after launch
 return $difference;
}

Thanks in advance!

A: 
function date2daycount($timestamp) {
 $launchDay =  strtotime('19 October 2009'); // launch (2009/10/19 00:00:00)
 $difference = floor(($timestamp-$launchDay)/86400); // days after launch
 return $difference+1;
}
Question Mark
Thank you for the answer, but strtotime('19 October 2009') gives back 1255903200 on my server. And this is what I've written in the question.
But what is the `-3600*24` for?
Question Mark
using strtotime is more verbose and readable when you come back to upgrade the system and modify this code
Question Mark
The -3600*24 is there because the 19th October should be day 1, not day 0. Yes, strtotime is more verbose. But it isn't correct yet. ;)