Re: Calculate date



On Jan 31, 10:18 am, "Shan" <Shani...@xxxxxxxxx> wrote:
I need help calculting a dta.

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.

so 10 should be conversted to 01/06/2007 and so forth.

The easiest way is going to be with Date::Calc's Add_Delta_Days
function:
$ perl -MDate::Calc=Add_Delta_Days -wle'
for my $delta (10, 89, 17) {
my ($y, $m, $d) = Add_Delta_Days(2007, 1, 16, -$delta);
print "1/16/2007 - $delta days = ", join "/", $m, $d, $y;
}
'
1/16/2007 - 10 days = 1/6/2007
1/16/2007 - 89 days = 10/19/2006
1/16/2007 - 17 days = 12/30/2006

If you have an aversion to installing the module for some reason,
you'll have to do the calculations manually: use Time::Local's
timelocal() function to get a timestamp for 1/16/2007, then subtract
from that the number of seconds that are in your given number of days,
then use the builtin localtime() to go from that newtime stamp back to
a series of seconds, minutes, hours, days, months, years, making sure
you take into account the odd values (year is actually year-1900,
month is actually month-1), not to mention leap-year problems....

Date::Calc takes care of all of the above for you. It's far easier.

Paul Lalli

.



Relevant Pages

  • Re: fixed-point
    ... point representation. ... To add or subtract two fixed point numbers, ... You wnat the result in fixed point format. ... than floating point, but not on modern machines because the floating point ...
    (comp.lang.c)
  • Re: Find in a date range
    ...    Set Field [DateField, ... Field above has to work out the current month and subtract 1. ... Captain) instead of a year month day or day month year format. ... But theDatefunction must have it's parameters in American order. ...
    (comp.databases.filemaker)
  • Re: Negative numbers
    ... is either 0 or 1, representing the absence or presence ... I meant to say in my last post that you can replace "subtract" by ... \ convert from normal to NZ format ... \ Then all you have to do is to convert all of the maths operations to ...
    (comp.lang.forth)
  • Re: Time Diff from text format
    ... Format the cell as Custom h:mm ... subtract 632 from 619 ... I have a file containing 50,000 lines containing scheduled times and actual ... scheduled time to determine how many minutes the bus was late. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Find in a date range
    ... The equivalent Script would then be something like: ... Assuming you mean a calendar month the calculation part of the Set ... Field above has to work out the current month and subtract 1. ... Captain) instead of a year month day or day month year format. ...
    (comp.databases.filemaker)