CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Date Rotuines

 



Wiliam
Novice

Aug 15, 2000, 2:12 AM

Post #1 of 5 (1005 views)
Date Rotuines Can't Post

Hi,

I need to compare two dates. At the moment my dates are sorted as:

ddmmyyyy

I need to subtract one from the other to be able to compare the difference. However, obviously this can't be done because the 1st of the 9th will have less of a difference than the 14th of the 1st.

Anyway, what I want to do is to convert my date into seconds or minutes of whatever. I need to know what I need to do to have both my dates in a format where I can easily compare them.

Any ideaS?

Wil.



randor
User

Aug 18, 2000, 4:07 AM

Post #2 of 5 (1005 views)
Re: Date Rotuines [In reply to] Can't Post

yes, you are correct, you cannot subtract from a formatted date like that, it will not turn out correct.
well, it is kinda hard to give suggestions without a bit more info, Did you convert it to the ddmmyyyy format? if you did, then i would suggest possibly using a 2 fold date, ie: when your script formats a date to ddmmyyyy, have it also send a unformated (in seconds that is) copy to a file, and use that when it is needed. This is with the assumptuion that you formatted the date for a reason other than strictly for kicks and giggles on your part, if not then just dont format it Smile

hope this helps
Randor


Wiliam
Novice

Aug 18, 2000, 6:42 AM

Post #3 of 5 (1005 views)
Re: Date Rotuines [In reply to] Can't Post

Hi Randor,

Thankyou for our help. I have converted my dates into ddmmyyyy format. What I really need to do now I guess is to convert that string into seconds or minutes? Or I could even convert that into days from 1900 or something. Anyway, the point is how do I go about doing this?

Regards,

Wiliam Stephens


rGeoffrey
User / Moderator

Aug 18, 2000, 12:43 PM

Post #4 of 5 (1005 views)
Re: Date Rotuines [In reply to] Can't Post

This is found in the Perl Cookbook (recipe 3.5) to calculate the number of days between two dates.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


use Date::Calc qw(Delta_Days);
$days = Delta_Days( $year1, $month1, $day1, $year2, $month2, $day2);
</pre><HR></BLOCKQUOTE>

Date::Calc is available from CPAN at...
http://search.cpan.org/search?dist=Date-Calc

I have not used it, but I have heard good things about it.


Wiliam
Novice

Aug 19, 2000, 9:04 AM

Post #5 of 5 (1005 views)
Re: Date Rotuines [In reply to] Can't Post

Thankyou, I'll look into this module!

Rgds,

Wiliam

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives