Gossamer Forum
Home : General : Perl Programming :

Convert yyyy-mm-dd format into UNIX timestamp...

Quote Reply
Convert yyyy-mm-dd format into UNIX timestamp...
Hi,

I'm trying to convert a normal date (i.e yyyy-mm-dd), into a UNIX timestamp. Thus far, I have;

date_transform ($date, '%yyyy%-%mm%-%dd%', '%yyyy%%m%%dd%%H%%MM%%ss%');

...but that doesn't seem to work right :/

Any ideas? Smile

TIA

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Convert yyyy-mm-dd format into UNIX timestamp... In reply to
Do you mean unixtime or timestamp?

You can't simply convert a date to unixtime by changing the format string since it needs to be converted into the seconds that have passed after 1970. This function will do the conversion:

Code:
sub {
my $year = 2005;
my $month = 9;
my $day = 21;

use Time::Local;
my $time = timelocal(0,0,0,$day,$month,$year);
return $time;
}
Quote Reply
Re: [Volker] Convert yyyy-mm-dd format into UNIX timestamp... In reply to
Bugfix:

Code:
sub {
my $year = 2005;
my $month = 9;
my $day = 21;

use Time::Local;
my $time = timelocal(0,0,0,$day,$month - 1,$year);
return $time;
}
Quote Reply
Re: [Volker] Convert yyyy-mm-dd format into UNIX timestamp... In reply to
Thanks =)
In Reply To:
Bugfix:

Code:
sub {
my $year = 2005;
my $month = 9;
my $day = 21;

use Time::Local;
my $time = timelocal(0,0,0,$day,$month - 1,$year);
return $time;
}

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!