[ale] Calculate Midnight in Perl

Jerry Yu jjj863 at gmail.com
Fri Jul 7 08:47:24 EDT 2006


so, could be all in (My)SQL, SELECT * FROM table1 WHERE date1  =  CURDATE()
- interval 1 day

hehehe, that 'great idea' didn't come easy: learned all this when I
consolidated six seven billing servers running FoxPro  on SCO OpenServer 5.

On 07 Jul 2006 08:35:11 -0400, Christopher Fowler <
cfowler at outpostsentinel.com> wrote:
>
> On Fri, 2006-07-07 at 06:45, Jerry Yu wrote:
> > if it is billing-type application, it'd be safer to run it at 00:01am
> > and calculate yesterday's DATE to use in your SQL.
>
> That is a great idea.  Never thought about that.   I typically run them
> at 23:57 so that I can get the correct day.  This is not billing it is a
> report on what users accessed what consoles and when they accessed those
> consoles.  I have a similar report that tells me what remote device(s)
> connected via PPP and how long they were connected.  Typically they only
> connect for about a minute+.  This gives them enough time to deliver
> their alarms.
>
>
> >
> > 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
> >
> >
> >
> > ______________________________________________________________________
> >
> > _______________________________________________
> > 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
>
-------------- next part --------------
An HTML attachment was scrubbed...




More information about the Ale mailing list