[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ale] Calculate Midnight in Perl
- Subject: [ale] Calculate Midnight in Perl
- From: cfowler at outpostsentinel.com (Christopher Fowler)
- Date: Thu, 06 Jul 2006 12:36:04 -0400
- In-reply-to: <[email protected]>
- References: <[email protected]>
I'm an idiot. Once I passed the correct value as isdst as reported by
localtime then everything worked great!
On Thu, 2006-07-06 at 12:25 -0400, Christopher Fowler wrote:
> I need to calculate midnight in perl so that I can do a select on a
> table and just get the current day's entries. Here is how I did it.
>
> --- [ Cut Here ] --------------
> #!/usr/bin/perl
>
> use POSIX;
> use strict;
>
> sub midnight {
> my $t = shift;
> $t = ($t ? $t : time());
> my (undef,undef,undef,$mday,$mon,$year,$wday,$yday,$isdst) =
> localtime($t);
> my $ti = POSIX::mktime(0, 0, 0, $mday, $mon, $year, 0, 0 ,0);
> return $ti;
>
> }
>
> my $ti = midnight(time());
> print POSIX::ctime($ti);
> --- [ Cut Here ] --------------
>
> Output:
> --- [ Cut Here ] --------------
> [cfowler at shuttle ~]$ ./midnight.pl
> Thu Jul 6 01:00:00 2006
> --- [ Cut Here ] --------------
>
> Is it saying that 1am is the time since I'm on EDT now?
> I was expecting 00:00:00
>
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale