Gossamer Forum
Home : Products : Gossamer Forum : Discussion :

How to add hours to a time variable ?

Quote Reply
How to add hours to a time variable ?
Hi,

In a template I print the current time with the variable <%GT::Date::date_get(0, "%H%:%MM%")%>. How can I add directly in the template a specific number of hours to this variable (example: <%GT::Date::date_get + x hours (0, "%H%:%MM% (%d% %mmmm% %yyyy%)")%>)? How can I do that? What is the exact syntax to use?

Thank you very much!

François

Last edited by:

Franco: Oct 29, 2002, 12:35 PM
Quote Reply
Re: [Franco] How to add hours to a time variable ? In reply to
Hi François,

You're going to need a global in order to that - just to get the current time.

So the global current_time will contain: sub { time }

Now, in the template, do something like this:

<%set my_time = current_time%>
<%set my_time += 3600%> # 3600 for 1 hour, #7200 for two hours, etc.
<%GT::Date::date_get($my_time, "%H%:%MM%")%>

You could throw another step in there if you need to dynamically handle the offset:

<%set my_time = current_time%>
<%set my_time_offset = 2%> # 2 hours, for example, or $tagname if it's in a tag
<%set my_time_offset *= 3600%>
<%set my_time += $my_time_offset%>
<%GT::Date::date_get($my_time, "%H%:%MM%")%>

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Quote Reply
Re: [Jagerman] How to add hours to a time variable ? In reply to
Thank you, Jason!

I tried this:

<!--<%GForum::init_date%>-->
<%set my_time = current_time%>
<%set my_time_offset = 6%>
<%set my_time_offset *= 3600%>
<%set my_time += $my_time_offset%>
<%GT::Date::date_get($my_time, "%H%:%MM% (%d% %mmmm% %yyyy%)")%>

But I get the result: 1:03 (1 janvier 1970) ?? Do you know where come from the problem.

Thank you very much!

François
Quote Reply
Re: [Franco] How to add hours to a time variable ? In reply to
Hi François,

My mistake Blush - the first set tag should be:

<%set my_time = $current_time%>

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com