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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert decimal hours to HH:MM format in Crystal Report 1

Status
Not open for further replies.

pgeorge33

Programmer
Jun 5, 2012
4
US
I have an application written in C#.net using VS 2008 and Crystal Reports. I have written reports that pull data from my access database and bind the data to the crystal report where the data is summarized and totaled in various ways. One of my customers has requested that instead of displaying the hours in decimal hours (example 6.25) they would like all of the time fields displayed in HH:MM format (example 6:15) Is there a way within Crystal Reports to do the conversion from 6.25 to 6:15? If not, any ideas on the best way to accomplish this? Many of my totals are done in my SQL statement and others are done inside of the report.

Thanks for any insight.

Pete
 
Well, try this the math does work. take your decimal value, say.25 and multiple by .6 the result is .15. I have done the math, and it works thru.9 for the decimal, which equals out to .54. A tenth of an hour ahould be 6 minutes.
 
numbervar dec := {table.dechrs};
numbervar hrs := truncate(dec);
numbervar mins := remainder(dec,truncate(dec))*60;
stringvar hhmm := totext(hrs,0,"")+":"+totext(mins,"00")

-LB
 
Thanks for your response. Where do I write the code to accomplish this conversion? In my reports I typically have values in the details and group Footer sections that will need to be converted, but I have not been able to figure out how to get "Behind" those values to write the code. I'm new to CR and find it's not very intuitive.

 
I think I am making progress. Figured out how to generate a formula and add the simple code behind it... I'll let you know how I make out. Thanks again.

Pete
 
Thanks LB for your help. I got it working after a little playing around. I was having with "divide by zero" errors popping up so I ended up checking for zero first and calculating the minutes differently. (The remainder function was throwing the error). The final code I used looks like this (I went the basic route since I was more familiar with it...)

dim dec as number
dim hrs as number
dim mins as number
dim hhmm as string

dec = {Cards.Reg Hours}

if dec = 0 then
formula = "00:00"

else

hrs = truncate (dec)
mins = (dec - hrs) * 60
hhmm = totext(hrs,0,"") & ":" & totext(mins,"00")
formula = hhmm

end if

Thanks again for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top