View previous topic :: View next topic |
Author |
Message |
Starfox Tux's lil' helper
Joined: 04 Sep 2002 Posts: 93
|
Posted: Tue Dec 10, 2002 8:13 am Post subject: OT: date2int and vice versa in PERL |
|
|
Hi foks,
does anyone know a simple command or package (PERL) that is able to convert a date into an integer and vice versa???
I need something like
Code: | date2int($month,$day,$year) |
or similar.
Thx fox |
|
Back to top |
|
|
rac Bodhisattva
Joined: 30 May 2002 Posts: 6553 Location: Japanifornia
|
Posted: Tue Dec 10, 2002 8:16 am Post subject: |
|
|
Is this integer seconds since the epoch? If so, look at Time::Local, which contains timelocal and timegm. The inverse of this (split an epoch time into the Perl equivalent of a C struct tm) is localtime and gmtime. _________________ For every higher wall, there is a taller ladder |
|
Back to top |
|
|
Starfox Tux's lil' helper
Joined: 04 Sep 2002 Posts: 93
|
Posted: Tue Dec 10, 2002 8:26 am Post subject: |
|
|
hmm,
if possible i would prefer "interger days since the epoch", because i have to do something like:
Code: |
(($interger % 7 ) == $monday)
|
|
|
Back to top |
|
|
rac Bodhisattva
Joined: 30 May 2002 Posts: 6553 Location: Japanifornia
|
Posted: Tue Dec 10, 2002 8:39 am Post subject: |
|
|
Code: | #! /usr/bin/perl
use Time::Local;
my ($day, $month, $year) = (3, 10, 1981);
my @WEEKDAYS = ( 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat' );
my $secs = timelocal( 0, 0, 0, $day, $month-1, $year );
my @tm = localtime( $secs );
print $WEEKDAYS[$tm[6]], "\n"; |
The "month-1" is because months are counted from 0 in localtime land. See the perlfunc man page (or look at the C struct tm) to see that [6] is the day of the week, and 0 = sunday there. You can combine the timelocal and localtime commands, without the $secs intermediate variable, but I put it in for clarity. Is this what you are looking for? _________________ For every higher wall, there is a taller ladder |
|
Back to top |
|
|
Starfox Tux's lil' helper
Joined: 04 Sep 2002 Posts: 93
|
Posted: Tue Dec 10, 2002 10:17 am Post subject: |
|
|
[I will test it out later.]
Hmm, i think this is nearly exactly what i need!!!
Thank you very much!!! |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|