* spelling and grammar fixes * How can I compare two dates and find the difference? + rewrote answer to mention the several Date packages on CPAN
Index: perlfaq4.pod =================================================================== RCS file: /cvs/public/perlfaq/perlfaq4.pod,v retrieving revision 1.65 diff -u -d -r1.65 perlfaq4.pod --- perlfaq4.pod 4 Jun 2005 04:12:40 -0000 1.65 +++ perlfaq4.pod 2 Aug 2005 22:16:30 -0000 @@ -409,7 +409,7 @@ my $week_of_year = strftime "%W", localtime( timelocal( 0, 0, 0, 18, 11, 1987 ) ); -The Date::Calc module provides two functions for to calculate these. +The Date::Calc module provides two functions to calculate these. use Date::Calc; my $day_of_year = Day_of_Year( 1987, 12, 18 ); @@ -436,15 +436,12 @@ =head2 How can I compare two dates and find the difference? -If you're storing your dates as epoch seconds then simply subtract one -from the other. If you've got a structured date (distinct year, day, -month, hour, minute, seconds values), then for reasons of accessibility, -simplicity, and efficiency, merely use either timelocal or timegm (from -the Time::Local module in the standard distribution) to reduce structured -dates to epoch seconds. However, if you don't know the precise format of -your dates, then you should probably use either of the Date::Manip and -Date::Calc modules from CPAN before you go hacking up your own parsing -routine to handle arbitrary date formats. +(contributed by brian d foy) + +You could just store all your dates as a number and then subtract. Life +isn't always that simple though. If you want to work with formatted +dates, the Date::Manip, Date::Calc, or DateTime modules can help you. + =head2 How can I take a string and turn it into epoch seconds? @@ -593,7 +590,7 @@ This is documented in L<perlref>, and although it's not the easiest thing to read, it does work. In each of these examples, we call the function inside the braces of used to dereference a reference. If we -have a more than one return value, we can contruct and dereference an +have a more than one return value, we can construct and dereference an anonymous array. In this case, we call the function in list context. print "The time values are @{ [localtime] }.\n"; -- brian d foy, [EMAIL PROTECTED]