Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Number to Time conversion 1

Status
Not open for further replies.
Jan 28, 2004
19
US
I have a table that store appointment time as numbers. e.g 32400 should be 9:00 AM and 36400 should be 10:00 AM.

I am using Crystal Report 11 - Is there a function i could use to do the conversation?

I would like to convert a number to hour and minutes

32400 TO 9:00 AM


Thanks again
 
I had a similar problem a while back, I personally did not find a function for it but created a formula.

I'm racing to catch my train so the code this can definately be cleaner (my original formula was comparing dates and counting the time lapse) but it should give you the idea:


local numbervar TOTAL;
local numbervar min;
local numbervar hr;
local stringvar AMPM;
local stringvar message;

TOTAL := {YourTimeField};
AMPM := "AM";
hr := truncate(TOTAL /3600);
min := remainder(TOTAL/3600,1) * 60;

if hr > 12 then
(
hr := hr - 12;
AMPM := "PM";
);
if TOTAL = 43200 then AMPM := "PM";
if TOTAL = 86400 then AMPM := "AM";

message := totext(hr,0) + ":" + totext(min,'00') + AMPM;
 
If you use a formula like the following:

numbervar x := {table.number};
dateadd("s", x, datetime(currentdate, time(0,0,0)));

...result will be a datetime which you can then right click on->format->date and time->time->choose the desired elements of the display.

-LB
 
I forgot to mention that the formula was from Crystal Report 7 that did not have the DateAdd function.

LB's solution is a "little" cleaner

; )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top