Gossamer Forum
Home : Products : Gossamer Links : Discussions :

How to change a date into Unix time?

Quote Reply
How to change a date into Unix time?
Hi,

In a template, I need in to change a date ("%yyyy%-%mm%-%dd%") into Unix time. How can I do that?

Thank you very much.

François
Quote Reply
Re: [Franco] How to change a date into Unix time? In reply to
Hi,

You could do it with a quick global:

Code:
sub {
my $date = shift;
my @time = GT::Date::parse_format($date, "format string");
my $unix_time = GT::Date::timelocal(@time);
return $unix_time || 'Unparseable date';
}

parse_format() returns an array of values like you would get out of localtime(). timelocal converts that array into a unix time.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] How to change a date into Unix time? In reply to
Hello,

I would like to be able to convert a date with the Unix time.

If I use your global <%global_name%>, it converted the current date.

It is possible to obtain the conversion of a field ?

I have a Date_Day field which I would like to convert.

I tested this <%global_name($Date_Day)%> but, that does not function...

Thank you for your assistance.

Mick