[ale] Calculate Midnight in Perl

James Sumners james.sumners at gmail.com
Thu Jul 6 12:51:25 EDT 2006


>From http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html :

CURDATE()

Returns the current date as a value in 'YYYY-MM-DD' or YYYYMMDD
format, depending on whether the function is used in a string or
numeric context.

mysql> SELECT CURDATE();
        -> '1997-12-15'
mysql> SELECT CURDATE() + 0;
        -> 19971215

On 7/6/06, Christopher Fowler <cfowler at outpostsentinel.com> wrote:
> On Thu, 2006-07-06 at 12:37 -0400, James Sumners wrote:
> > Why not just `SELECT * FROM table WHERE date_col = CURDATE();`? (If
> > you are using MySQL. I assume other DBs have the same sort of
> > functionality.)
>
> Is that midnight?  Or does CURDATE() imply today only?  I want to run
> the report at 11:59pm and only get rows for that day.
>
> >
> >
> > On 7/6/06, Christopher Fowler <cfowler at outpostsentinel.com> 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
> > >
> >
> >
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
>


-- 
James Sumners
http://james.roomfullofmirrors.com/

"All governments suffer a recurring problem: Power attracts
pathological personalities. It is not that power corrupts but that it
is magnetic to the corruptible. Such people have a tendency to become
drunk on violence, a condition to which they are quickly addicted."

Missionaria Protectiva, Text QIV (decto)
CH:D 59



More information about the Ale mailing list