Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Date time calculations

Quote Reply
Date time calculations
I need to substract two dates in the format 'YYYY-MM-DD HH:MM:ss' from each other and get the result in the format 'days HH:MM:ss'.

I have tried to write various globals (taking two datetime arguments) using date_sub, but it ignores the HH:MM:ss and is therefore not useful.. I have read through the GT::Date documentation without much luck - any help / hints highly appreciated.



Anders
Quote Reply
Re: [vespa180] Date time calculations In reply to
Try the global below:

sub {
my ($date, $format) = @_;
require GT::Date;
my $unix_time = GT::Date::timelocal(GT::Date::parse_format($date, "%yyyy%-%mm%-%dd% %hh%:%MM%:%ss%"));
return GT::Date::date_get($unix_time, $format);
}

Now you can use:
<%global_name($var_date, "%HH%:%MMM%:%ss%")%>

Hope that helps,
TheStone.

B.
Quote Reply
Re: [TheStone] Date time calculations In reply to
Thanks alot The Stone - your hint helped me get started.

But I have a new problem now.. I cant use the modulus opperator i/ with set statements ex:

<% set days = $date_in seconds i/ 864000 %> does not assign $date_in seconds i/ 864000 to $days..

If I only write <% $date_in_seconds i/ 86400%> it works perfect, but I cant pick up the result for futher calculations..

Any ideas?



Anders
Quote Reply
Re: [vespa180] Date time calculations In reply to
You have to use the global template:

sub {
my $tags = GT::Tenplate->tags;
my $days = $date_in_seconds i/864000%>
....
}

TheStone.

B.