Re: Perl time and Mysql time
- From: "Mothra" <mothra@xxxxxxxxxxxxxxxx>
- Date: Tue, 27 Sep 2005 08:37:25 -0700
Hello Phal,
phal wrote:
> Dear friend
>
> Actually, the problem not concern under MySQL, my main problem is how
> I going to compare the Date-time after I had retrieved from MySQL
> database. If the time in database is older then the current_time, the
> program will print expire, and user cannot see the information. On the
> other hand, it will keep print till the time expired. When the time
> expired? Yes, during record the TIME and DURATION in database, the
> TIME + DURATION will recorded,
>
This may work for you
use strict;
use warnings;
use DateTime;
use DateTime::Format::Mysql;
use DateTime::Duration;
my $today = DateTime->now();
my $d = DateTime::Duration->new(
days => '4',
hours => '5',
);
while (<DATA>) {
my $dt = DateTime::Format::MySQL->parse_datetime($_);
if ( $today + $d > $dt ) {
print "Today plus the duration is greater than\n";
}
elsif ( $today + $d < $dt ) {
print "Today plus the duration is less than\n";
}
elsif ( $today + $d == $dt ) {
print " Today plus the duration is equal\n";
}
}
__DATA__
2003-01-16 23:12:01
2004-05-06 11:15:55
2005-10-16 15:12:00
Hope this helps
Mothra
.
- References:
- Perl time and Mysql time
- From: phal
- Re: Perl time and Mysql time
- From: Chad Hanna
- Re: Perl time and Mysql time
- From: phal
- Perl time and Mysql time
- Prev by Date: Re: Help with regexp. Can you do better
- Next by Date: Re: FAQ .
- Previous by thread: Re: Perl time and Mysql time
- Next by thread: FAQ 8.20 How can I call my system's unique C functions from Perl?
- Index(es):
Relevant Pages
|