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

Converting number to HH:MM 1

Status
Not open for further replies.

acessn

Programmer
Feb 16, 2005
71
NO
Using cr9.0

I use this formula to convert a number to hh:mm
Code:
NumberVar nbrTime := {@number};
NumberVar nbrHour := Truncate(nbrTime);
NumberVar nbrHold := (nbrTime-nbrHour)*100;
nbrHold := (60*nbrHold)/100;
NumberVar nbrMinute := Truncate(nbrHold);

ToText(nbrHour,0,"") + ":" + ToText(nbrMinute,0,"") + ":"

The problem is that when number is i.e. 65, it displays 65:0 instead of 65:00. It works fine with 65.5 which is displayed 65:30.

Does anyone know how to fix this?

Regards,
Bjorn
 
Try

If nbrMinute = 0 then
ToText(nbrHour,0,"") + ":" + "00" + ":" else
ToText(nbrHour,0,"") + ":" + ToText(nbrMinute,0,"") + ":"

Ian

 
Hi Bjorn,

I think the right approach is:

ToText(nbrHour,"00") + ":" + ToText(nbrMinute,"00")

You don't have to verify the nbrMinute variable.

Regards
vxxv
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top