Gossamer Forum
Skip to Content



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.com



Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
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.com



Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates