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

Changing 14:45 (as a string) into actual time

Status
Not open for further replies.

Oglesbay

Instructor
May 5, 2006
71
US
Hi all. My start times and end times are set as string and stored in military time without seconds. (eg. 14:45) What I would like to do is have the converted into actual time or a number, which ever one will allow me to calculate the difference between the two.

I saw many threads on changing the string to number using the "tonumber" formula, but I just couldn't get it to work. Anyone have any ideas? Thanks.

Chad
 
Assuming you have no null values and the length of the times are 4 characters, then

//@StartDate
loval stringvar x := {table.starttime};
local numbervar h := tonumber(left(x,2));
local numbervar m := tonumber(right(x,2));

totext(datetime(date({table.startdate}),time(h,m,0)),"MM/dd/yyyy HH:mm:ss")
 
You should be able to do the following:

datediff("n",datetime(currentdate,time({table.starttime})),datetime(currentdate,time({table.endtime})))

//where n would give you the difference in minutes.

-LB
 
Thanks lbass... that worked perfectly! I just divided the total by 60 to get the total hours.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top