Re: Calculate date



On Jan 31, 4:27 pm, Purl Gurl <purlg...@xxxxxxxxxxxx> wrote:
Shan wrote:
I need help calculting a dta.

"calculating" "date"

http://www.google.com/search?q=%22spelling+flames

My data is in the following format
10
89
17
10
The above means 10 days ago, 89 days ago, 17 days ago, etc from
01.16/2007. I need to claculate the exact dates.

You have failed to define "day" for usage. A presumption is
this is a time period measured from midnight to midnight over
a period of twenty-four hours.

This presumption is, of course, one of the classic newbie programmer
mistakes that us veterans have seen repeated over and over.

In fact, in most parts of the world, there's one day in the year
that's 23 hours and one that's 25 hours. In some places ISTR there are
(were?) more than one of each.

Simple arithmetic. Convert your 01/16/2007 date to epoch seconds.
Subtract your "days back" in epoch seconds. Use your resultant
epoch seconds to print a date.

use Time::Local;

$base_day_epoch = timelocal (0, 0, 0, 16, 0, 2007);

To avoid nasty surprises make the 3rd 0 be 12 (i.e. midday).

Alternatively use timegm() and gmtime() rather than timelocal() and
localtime() since in UCT the days are all the same length. Leap
seconds can be ignored because they are blurred out in the normal
definition of epoch time.

.