12 hour time format

Question

• Hello,

I am doing a program that will compute the time in and time out.  As much as possible I want to do the time() function and not the datetime() function but the problem is if I use time() it displays the 24 hour format.  What I am tasked to do is to subtruct the time out to time in and be able to display the 12 hour format. Any advice will be greatly appreciated.

Tuesday, November 29, 2005 9:37 AM

• set hours to 12
? ttoc(datetime(),2)
? time()
Tuesday, November 29, 2005 10:08 AM

All replies

• set hours to 12
? ttoc(datetime(),2)
? time()
Tuesday, November 29, 2005 10:08 AM
• Thanks for the response. I have a follow up question how can i make the two text boxes containing the time in and time out to computer the number of hours worked? This is the codes I'm working on right now, do you have any suggestions that will make it easier?  The problem with this is it sums up the total of hour and minute like the 1 hour and 5 minutes making it 1+5 = 6 hours and not 1 hr 5 min.

thour = 0.00
tminute = 0.00

* hour
thour = val(alltrim(substr(thisform.txtctimeout.value,1,2))) - val(alltrim(substr(thisform.txtctimein.value,1,2)))

* minute
tminute = val(alltrim(substr(thisform.txtctimeout.value,4,2))) - val(alltrim(substr(thisform.txtctimein.value,4,2)))

Wednesday, November 30, 2005 5:21 AM
• As I understand both times are on the same day.

set hours to 24
cTime1 = '01:00 AM'
cTime2 = '04:05 PM'
? Ttoc( Ctot('0') + ( Ctot( m.cTime2 ) - Ctot( m.cTime1 ) ), 2)
set hours to 12

Here is how it works:

Ctot('0'), Ctot( m.cTime2 ) and Ctot( m.cTime1 ) return those values as datetime values (date part defaults to base ^1899/12/30).
Ctot( m.cTime2 ) - Ctot( m.cTime1 ) gives the difference between two times in seconds. Ctot('0') is midnigth - ^1899/12/30 00:00. Adding Ctot( '0' ) + differenceInSeconds gives a new datetime value. Time part of this new value is the time person worked and you get it as a time string with the outermost ttoc(,2). Setting hours to 24 in case person might have worked over 12 hours.

PS: This only works if both Time1 and Time2 are on the same day.
I suggest you not to simply only store time. Store them as datetimes. Person might start working near midnight and end working in the morning (ie: night shifts). Then you would simply subtarct two datetimes to get difference in seconds which you might format as you want.

Wednesday, November 30, 2005 10:02 AM
• Another way – try this

Local lnHStart, lnHEnd, lnHour, lnEnd, lnTime, lcTime

Set Hours to 24

lnHEnd = Val(Left(thisform.txtctimeout.value,2))*60

lnHStart = Val(Left(thisform.txtctimein.value,2))*60

lnHEnd = m.lnHEnd + Val(Right(thisform.txtctimeout.value,2))

lnHStart = m.lnHStart + Val(Right(thisform.txtctimein.value,2))

lnTime = m.lnHEnd – m.lnHStart

lnHour = Int(m.lnTime/60)

lnMin = m.lnTime – m.lnHour * 60

lcTime = Transform(m.lnHour,”@L 99”)+”:”+Tranform(m.lnMin,”@L 99”)

Set Hours to 12

Manoj

Nepal

Wednesday, November 30, 2005 11:02 AM
Thursday, December 01, 2005 2:15 AM
• Hi,

Have you considered what happens when someone works from 8:00 on Monday to 8:01 on Tuesday? Without the date portion your program would show that person as working for one minute.
Thursday, December 01, 2005 11:37 PM
• Hi Cindy,

I did not include the date on my question but in the program every important info like the date is included. I just want to make my question short just to focus on the time format.  Thanks for reading
Friday, December 02, 2005 2:39 AM
• But if you're storing both the date and the time, why not use a single datetime field rather than having to do all this extra work?

Tamar
Friday, December 02, 2005 9:37 PM
• Tamar,
Since I also have an in-out tracking system in use I can understand why he has to. Endusers want to see entries something like:

Date: Monday, Feb 14, 2005
In: 11:07 PM
Out: 07:12 AM
Period: 08:05

Yes out is on Tuesday morning but to them it belongs to Monday's view (a night shift). Actual data is stored as datetime.
Saturday, December 03, 2005 1:16 PM
• But surely that's a display issue, not a data storage issue.

Tamar
Monday, December 05, 2005 9:41 PM