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

convert string to time 2

Status
Not open for further replies.

jrhessey

IS-IT--Management
Feb 25, 2005
37
0
0
Hey guys, I've got a couple fields I'd like to convert to time. The string looks like 6.000 or 20.500. Both values would be 6:00am and 8:30pm. I'd like to get it to a time format as well so I can append it to the date using the dateime function. I've googled and everything I have tried has either resulted in a bad string time format or 12:00:00. I've tried ctime, time, also tried extacting the hours and minutes, but I can't get it to convert to a time format. Any help would be greatly appreciated. Thanks!!
 

Not particularly elegant, but it works for your two examples - please test further.

whileprintingrecords;
stringvar v_hours := split(totext({YourField},"#.##",2),".")[1];
stringvar v_minutes := split(totext({YourField},"#.##",2),".")[2];

time(v_hours & ":" & totext(tonumber(v_minutes)*.6,"#",0))

 
Brian, thanks for your reply!!

I get an error, "to many arguments have been given to this function," and the "#.##",2 is highlighted in the first variable.

Code:
whileprintingrecords;
stringvar v_hours := split(totext({WOO_HistoryTransaction.StartTime},[highlight #729FCF]"#.##",2[/highlight]),".")[1];
stringvar v_minutes := split(totext({WOO_HistoryTransaction.StartTime},"#.##",2),".")[2];

time(v_hours & ":" & totext(tonumber(v_minutes)*.6,"#",0))
 
You have a string (6.0 & 20.5) which are, if converted to a number, are the HOURS in the DAY.

So counvert the HOURS to DAYS by dividin the numeric value by 24, and now you have a Date/Time value, that you ought to be able to format like any other data/tive value.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 

You specified that your source field was a string but I missed that - regardless, I knew there was a better way so Skip's formula works perfectly:

time(tonumber({WOO_HistoryTransaction.StartTime})/24)

 
That worked, awesome! Thank you both for taking the time to answer!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top