|
Tip>Designer |
|
|
Determining the time elapsed between two dates |
|
|
Article #: |
0026 |
|
Contributor: |
Joanne Irvine-Smith |
|
GF version: |
All |
|
Applies to: |
Date and Time tasks |
|
Last updated: |
December 19, 2001 |
Description
Determine the number of days, hours and minutes that have elapsed between two dates.
Explanation
Using the Date and Time tasks, you can set up FillPoints that will use the system date and time to determine the time that has elapsed between an original date and the date at run time.
Click here to view the example.
%[DateOpened=Calendar.Capture("Caption",Date())]
opens the calendar interface and allows you to browse through the calendar to choose an original date. The time portion of a date selected in this way is always 12 am. You can add half a day to the Date to get 12 pm:
%[DateOpened=DateOpened+0.5]
%[DateClosed=Now()]
stores the current system date and time in the DateClosed variable.
Days: %[Calendar.Days(DateOpened,DateClosed)]
This task determines the number of days between the two dates.
There are no similar GhostFill tasks to determine the time difference between two dates. However, dates are represented internally as numbers (days since 30 December 1899), so you can use a standard mathematical calculation to calculate the hours and minutes:
%[DateDif=DateClosed-DateOpened)]
The result of this subtraction can then be formatted as hours and minutes:
Hours and minutes: %[FormatTime(DateDif,'h:mm')]