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 TIme, Number is in format of 163,321.00

Status
Not open for further replies.

mintman

IS-IT--Management
Mar 5, 2007
66
US
Hello all I need to conver the number to time numbers can be of format 163,321.00 or 93,429.00
I did this

FORMULA FOR “@PHPTCR”
if tonumber({PHPICK00.PHPTCR})<100
then "0000"+ totext(tonumber({PHPICK00.PHPTCR}))else if
tonumber({PHPICK00.PHPTCR})<1000
then "000"+ totext(tonumber({PHPICK00.PHPTCR}))else if
tonumber({PHPICK00.PHPTCR})<10000
then "00"+ totext(tonumber({PHPICK00.PHPTCR}))else if
tonumber({PHPICK00.PHPTCR})<100000
then "0"+ totext(tonumber({PHPICK00.PHPTCR}))
else totext({PHPICK00.PHPTCR})

FORMULA FOR “@PHPTCR_TIME”
if tonumber({PHPICK00.PHPTCR})>0
then TIME(left ({@PHPTCR},2)+ ":"+ mid ({@PHPTCR},3,1)+mid ({@PHPTCR},5,1)+ ":" + mid({@PHPTCR},6,2))


The second formula is bringing the resulting text into a formatted field that looks like 00:04:32. However, this field is still stored just as a text string and therefore we can not do any math against it. This text can be translated into a time that we can act on by putting the formula within the function TIME().

Any other suggestion on this...simple way or more efficient way?.


 
I would do all the math on the unformatted time value and store the result in a variable so you can reference it later on. Then you can convert the time to a string using a formula similiar to this:

@convert number to time
numberVar hrs:=0;
numberVar min:=0;
numberVar sec:=0;
stringVar hhmmss:=totext(hrs, "0") + ":" + totext(min, "00") + ":" + totext(sec, "00");

hrs := Truncate(Truncate({TimeField}/60)/60);
min := Remainder(Truncate({TimeField}/60),60);
sec := Remainder({TimeField},60);
hhmmss := totext(hrs, "0") + ":" + totext(min, "00") + ":" + totext(sec, "00");
hhmmss;
 
I will give this a try. Thanks for the info AKS.
M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top