Ronnie has asked for the wisdom of the Perl Monks concerning the following question:
br Running with the above params results in -#!/usr/bin/perl -w # use Time::Local ; # my $sec1 = '01' ; my $min1 = '00' ; my $hour1 = '00' ; my $day1 = '24' ; my $mon1 = '02' ; my $year1 = '2005' ; my $TIME1 = undef ; my $date1 = undef ; # my $tm = undef ; my $now = time ; # my $sec2 = '01' ; my $min2 = '00' ; my $hour2 = '00' ; my $day2 = '25' ; my $mon2 = '02' ; my $year2 = '2005' ; my $TIME2 = undef ; my $date2 = undef ; # print "\n\tTimestamp test begins\n" ; # $TIME1 = timegm($sec1,$min1,$hour1,$day1,$mon1,$year1) ; # print "\n\tTimestamp1 :: $TIME1\n" ; # ($sec1,$min1,$hour1,$day1,$mon1,$year1) = gmtime($TIME1) ; print "\n\tDay :: $day1" ; print "\n\tMon :: $mon1" ; $year1 += 1900 ; print "\n\tYear :: $year1\n" ; # print "\n\tDATE1 :: $year1\/$mon1\/$day1\n" ; # $TIME2 = timegm($sec2,$min2,$hour2,$day2,$mon2,$year2) ; # print "\n\tTimestamp2 :: $TIME2\n" ; # ($sec2,$min2,$hour2,$day2,$mon2,$year2) = gmtime($TIME2) ; print "\n\tDay :: $day2" ; print "\n\tMon :: $mon2" ; $year2 += 1900 ; print "\n\tYear :: $year2\n" ; # print "\n\tDATE2 :: $year2\/$mon2\/$day2\n" ; # my $dif = $TIME2 - $TIME1 ; my $days = ($dif / (60 * 60 * 24)) ; # print "\n\tThe difference is :: $days\n" ; # print "\n\tTimestamp test ends\n" ;
Using the following parameters however -$ xxrctimestamp.pl Timestamp test begins Timestamp1 :: 1111622401 Day :: 24 Mon :: 2 Year :: 2005 DATE1 :: 2005/2/24 Timestamp2 :: 1111708801 Day :: 25 Mon :: 2 Year :: 2005 DATE2 :: 2005/2/25 The difference is :: 1 Timestamp test ends $
br Results in the less than successful -my $sec1 = '01' ; my $min1 = '00' ; my $hour1 = '00' ; my $day1 = '31' ; my $mon1 = '10' ; my $year1 = '2005' ; my $TIME1 = undef ; my $date1 = undef ; # my $tm = undef ; my $now = time ; # my $sec2 = '01' ; my $min2 = '00' ; my $hour2 = '00' ; my $day2 = '01' ; my $mon2 = '11' ; my $year2 = '2005' ; my $TIME2 = undef ; my $date2 = undef ;
If there is something mind bogglingly stupid/dumb about this please feel free to say because I can't see my error! Cheers, Ronnie$ xxrctimestamp.pl Timestamp test begins Timestamp1 :: 1133395201 Day :: 1 Mon :: 11 Year :: 2005 DATE1 :: 2005/11/1 Timestamp2 :: 1133395201 Day :: 1 Mon :: 11 Year :: 2005 DATE2 :: 2005/11/1 The difference is :: 0 Timestamp test ends
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Date/Timestamp Puzzle
by saintmike (Vicar) on Jun 20, 2005 at 17:08 UTC | |
|
Re: Date/Timestamp Puzzle
by Ido (Hermit) on Jun 20, 2005 at 17:28 UTC | |
by thundergnat (Deacon) on Jun 20, 2005 at 18:32 UTC |