Home > Archive > PERL Beginners > November 2005 > Date::Manip Delta_Format aprox question
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Date::Manip Delta_Format aprox question
|
|
| Rianne Ubbink 2005-11-17, 6:56 pm |
| Hello,
For a program that I'm writing atm I have to calculate the number of
months between two dates. The months format is 2005-11-17 and I've been
able to get a nice delta with the time in between de two dates.
I've done it like this:
$implantdate="2000-11-07"
$fudate="2005-11-15"
I've done a check that $fudate is an higher date then the implantdate.
So that I get an positive numer.
my $date1 = ParseDate($implantdate);
my $date2 = ParseDate($fudate);
my $delta = DateCalc($date1,$date2,\$err,1);
the 1 standing for approximate mode, then he uses yMwdhms
The delta between the two dates is +5:0:1:1:0:0:0
So thats 5 years 0 months 1 w and 1 day
To get the date I tried:
my @format;
$format[0] = "%Mt";
my $str = Delta_Format($delta,2,@format);
Like this the output of string is: str=60.00
But with this it didnt take a look at the w s, days etc
I've found out that it was because of
<quote cpan>
Delta_Format can operate in two modes: exact and approximate. The exact
mode is done by default. Approximate mode can be done by passing in the
string "approx" as the 2nd argument.
In exact mode, Delta_Format only understands "exact" relationships. This
means that there can be no mixing of the Y/M and W/D/H/MN/S segments
because the relationship because, depending on when the delta occurs,
there is no exact relation between the number of years or months and the
number of days. </quote cpan>
but when I take a look at the Cpan for the complete function:
$str = Delta_Format($delta [,$mode], $dec,@format);
I'm stuck
I've tried a number of things
$str = Delta_Format($delta,"approx",2,@format);
The output of str is then str=2 60.000000
So for one reason or another it makes 2 also a string. And it doesnt use
it anymore. I also tried to put the approx in the $delta .. well
ofcourse that didnt work either.
And I did set the correct timezone for Date::Manip
I cant seem to find anything other in the manpages about this. And on
the web I cant seem to find anyone that uses the approx.
I really hope that you guys can help me on this matter
Thanks in advance
Rianne Ubbink
| |
| Dermot Paikkos 2005-11-17, 6:56 pm |
| On 17 Nov 2005 at 11:36, Rianne Ubbink wrote:
> Hello,
>
> For a program that I'm writing atm I have to calculate the number of
> months between two dates. The months format is 2005-11-17 and I've been
> able to get a nice delta with the time in between de two dates.
>
This sounds like a jobs for Date::Calc's Delta_YMD() function.
Dp.
| |
| usenet@DavidFilmer.com 2005-11-17, 6:56 pm |
| Rianne Ubbink wrote:
> For a program that I'm writing atm I have to calculate the number of
> months between two dates.
What does that mean? What if you have two dates:
2005-06-01 # June 1
2005-07-31 # July 30
How many "months" are between these two dates? You could answer it
three ways:
- There are no months "between" June and July; the answer is zero.
- July is one month past June, so the answer is one.
- A month is ~30.4 days; this is ~60 days so the answer is two.
Which is your intent to answer this question? Zero, one or two? You
need to clarify your intent if you hope to get a clear answer. Please
post a reply with the answer to this question: how many "months" are
between 2005-06-01 and 2005-07-31?
|
|
|
|
|