times

Maurice

New Member
What's the best way to let users enter times (like 16:40 etc) and how to store these times in the database, so i can perform some calculations on them.
 

jamesmc

Member
Hi there Maurice,

I always store time information in the database as an Integer. this is so that when I report on the time I can use the standard progress commands and manipulate it as necessary.

BTW, if anyone reading this doesn't know: Progress time is always an integer and is the number of seconds from midnight of the current day. If you are at 12:01 am then Progress will report the time as 60 and if it is 10pm then it would be 79200. You then convert this integer value to a displayable value by using string(79200, "HH:MM:SS").

The way that I ask for users to input the time is as follows:

<BLOCKQUOTE><PRE><FONT face=verdana,arial,helvetica size=1>code:</FONT>
<HR>
<FONT size=2>
def var input-hours as inte.
def var input-minutes as inte.
def var w-due-time as cha format "xx:xx". /* 24 hour format time input */
def var w-duetime as int format "999999". /* Actual time result, this */
/* value is what is stored */
/* in the database. */

SETTIME:
do on error undo, retry:

update w-due-time with side-labels.

assign input-hours = integer (substring (w-due-time, 1, 2))
input-minutes = integer (substring (w-due-time, 3, 2)).

if (input-hours < 0) or (input-hours > 23) then
do:
message "Invalid time".
undo SETTIME, retry SETTIME.
end.

if (input-minutes < 0) or (input-minutes >=60) then
do:
message "Invalid time".
undo SETTIME, retry SETTIME.
end.

assign w-duetime = (input-hours * 60 + input-minutes) * 60.

display string(w-duetime, "HH:MM:SS") /* For checking calculation */
string(w-duetime, "HH:MM AM"). /* display several versions */

end. /* SETTIME */
</font>

</PRE>
<FONT face="arial, helvetica" size=2></BLOCKQUOTE>
<HR>
<BR>

HTH,
James.
<a href="mailto:james_mcateer@progressmail.com">E-Mail Me Here</A>

[Edited by jamesmc on 10-03-2000 at 10:26 AM]
 
Top