Re: Perl time and Mysql time



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


.



Relevant Pages

  • Re: Perl time and Mysql time
    ... 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 ... If the time in database is older then the current_time, ... program will print expire, and user cannot see the information. ...
    (comp.lang.perl.misc)
  • Re: [kde] Has the KDE Social/Semantic Desktop been worth the hassle to anyone?
    ... commercial stuff couldn't do without databases, but just to take mysql ... as an example since that was the first and probably most common akonadi ... backend, it's known for database version upgrades that need extra steps ...
    (KDE)
  • Re: MySQL Database problem (probably already solved in a message, but this is somewhat urgent)
    ... MySQL server has a database with a table, ... columns, an FSR column, and a password column. ... checked if the supposed arrays that were returned were actually arrays ...
    (comp.lang.php)
  • RE: FreeBSD 5.3 MySQL Performance
    ... versions of Linux and FreeBSD for most tests. ... > popular with the ATA disk drive manufacturers. ... > Many companies have used FreeBSD and MySQL for years and years. ... it is not often that you have such a small database and such a large ...
    (freebsd-questions)
  • ANN: Database Designer for MySQL version 1.6 is released
    ... The new version 1.6 of MicroOLAP Database Designer for MySQL has been ... The secure shell (SSH) tunneling is now implemented in Database ...
    (borland.public.delphi.thirdpartytools.general)