Creating a Date-Time DataType. This is the article I wrote for Progressions.
Progress has a Date datatype and Time datatype, but not a Date-Time datatype. You can create one as a decimal. The idea is to add the two together into a decimal field to create the Date-Time datatype. This is really nice because you don't have to do any complex or weird logic to determine if you crossed the 24 hour mark. It would really be useful for calculating the difference between several days.
We have several processes that run at night and track the Last Run Date
and Last Run Time, and if it ran successfully. Each morning a report runs
displaying processes that didn't complete, the Last Run Date, and the
Last Run Time. So I will use these as the examples.
int(today) = an integer number representing today. You can
put this into a variable and use the date() function to display it:
time / 86400 gives you a fraction representing part of today.
09:58:52 = 36932. 36932 / 86400 is .4158796296. You can put this into
a variable and re-display it:
SO, you can put these two together into one decimal variable:
Ya, ok, so what, right?
Where this really becomes cool is when you are doing date-time calculations
across the 24 hour mark, and especially multiple days. If we were to set
the last-run-date to int(today) + time / 86400 (the date and time the
process was last scheduled to be run, not today's date and time), then
we can easily calculate exactly how many days and HH:MM:SS it has been
since this process last run. For example:
Last Run Date = 11/01/02
Last Run Time = 02:31:47
Today = 11/05/02, 09:58:52
To get the number of days and HH:MM:SS since the last run, we subtract these:
Next we parse v-diff to get the number of days and HH:MM:SS since this process last ran:
So we can see that it has been 4 days, 7 hours, 43 minutes and 45 seconds
since this process last ran.
I would write functions as .p/.i's so these could be re-used. By making
then functions in a .i, you can call them within the display statement.
With .p's, you would have to have an output variable then use that variable
in the display statement.
Anyhow, it's a neat idea and would make doing date and time difference
calculations easier. You would need to make sure it's documented well
so others know what's going on and why.