Re: Calculate date
- From: Purl Gurl <purlgurl@xxxxxxxxxxxx>
- Date: Wed, 31 Jan 2007 08:27:01 -0800
Shan wrote:
I need help calculting a dta.
"calculating" "date"
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.
"01/16/2007" "calculate"
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.
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.
Base Date minus Difference equals Prior Date (all in epoch seconds)
#!perl
use Time::Local;
$base_day_epoch = timelocal (0, 0, 0, 16, 0, 2007);
@Previous_Days = qw (10 89 17 10);
for (@Previous_Days)
{
$difference_date_epoch = ($_ * 86400);
print "$_ days back from 1-16-2007 is: ", scalar localtime ($base_day_epoch - $difference_date_epoch), "\n";
}
PRINTED RESULTS:
10 days back from 1-16-2007 is: Sat Jan 6 00:00:00 2007
89 days back from 1-16-2007 is: Thu Oct 19 01:00:00 2006 (note hour oddity)
17 days back from 1-16-2007 is: Sat Dec 30 00:00:00 2006
10 days back from 1-16-2007 is: Sat Jan 6 00:00:00 2007
My method above will not work correctly in early 2038 year.
However, in thirty years, you will not care. Additionally,
this will fail for dates prior to late 1901 year. I tend
to doubt this will be a problem.
Research and reading, which you should have already performed,
will help you to understand components of my example and will
help you to learn how to modify my example to meet your needs.
Purl Gurl
.
- Follow-Ups:
- Re: Calculate date
- From: nobull67@xxxxxxxxx
- Re: Calculate date
- References:
- Calculate date
- From: Shan
- Calculate date
- Prev by Date: Re: Calculate date
- Next by Date: How to pass two dimensional array from java to perl using inline java
- Previous by thread: Re: Calculate date
- Next by thread: Re: Calculate date
- Index(es):