Ow,

Welcome to Perl Programming.  Below is an attempt:

#!/usr/bin/perl
require "timelocal.pl";

sub rdxtime
{
    my ( $date ) = @_ ;
    my @t = split(/[-:\s]/,$d);
    $t[0] -= 1900; $t[1] -= 1; # check manpage of localtime
    @t = reverse(@t);
    return timelocal(@t);
}

# Your sample input
$d = "2007-08-13 14:39:48";
print rdxtime ($d);


Regards
Soong


> -------- Original Message --------
> Subject:      [Slugnet] Help with Perl Datetime + Epoch
> Date:         Mon, 13 Aug 2007 14:42:06 +0800
> From:         Ow Mun Heng <[EMAIL PROTECTED]>
> To:   Myoss <[EMAIL PROTECTED]>, "Linux Users' Group (Singapore)" 
> <[email protected]>
> 
> 
> 
> Been struggling with a new script I'm porting over from bash because
> perl's DBI is much more elegant than my previous usage of sqsh.
> 
> I'm having trouble converting from a datetime into a unix epoch
> timestamp.
> 
> under bash, this is done.
> 
> date = YYYY-MM-DD HH:MM:SS
> epoch_date = date -d "$date" +%s
> 
> $date
> Mon Aug 13 14:39:48 MYT 2007
> $date -d "2007-08-13 14:39:48" +%s
> 1186987188
> 
> Under perl, I have no idea how this can be achieved.
> Neither localtime, timelocal or AFAICT, DateTime can achieve this
> easily.
> 
> 
> 
> _______________________________________________
> Slugnet mailing list
> [email protected]
> http://www.lugs.org.sg/mailman/listinfo/slugnet
> 
> 
> 


_______________________________________________
Slugnet mailing list
[email protected]
http://www.lugs.org.sg/mailman/listinfo/slugnet

Reply via email to