Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

Time Conversion

I need to convert a time that is a string value to a time value only - i want to subtract 2 times to get the difference- it will not allow it because of it being a string?

Trying to accomplish this:

Currently the 15:10:00 and other time is a string.

15:10:00  -  15:01:00  =  9:00
0
srodgers45
Asked:
srodgers45
  • 5
  • 4
1 Solution
 
mlmccCommented:
Try this formula

mlmcc
Local StringVar strStart := {YourStartTimeSring};
Local StringVar strEnd := "{YourEndTimeSring};
local Timevar tmStart;
local Timevar tmEnd;
local NumberVar nbrSeconds;
local NumberVar nbrMinutes;
local NumberVar nbrHours;

tmStart := TimeValue(strStart);
tmEnd := TimeValue(strEnd);
nbrSeconds := DateDiff('s',DateTime(CUrrentDate,tmStart), DateTime(CurrentDate,tmEnd));
nbrHours := nbrSeconds\3600;
nbrSeconds := nbrSeconds mod 3600;
nbrMinutes := nbrSeconds\60;
nbrSeconds := nbrSeconds mod 60;

TimeValue(nbrHours,nbrMinutes,nbrSeconds);

Open in new window

0
 
srodgers45Author Commented:
Sorry i should have added that I have a date field that goes with the time - just separate
When I tried the formula above it comes up with all the times starting at 12:00. Do I need to add the date to the time?  When it tried before to do this formula it did not show properly

DTSToDateTime({FDC_Trips.atpsdate}+{FDC_Trips.atpstime})

The time shown on the left in the screen shot is the proper time. The time on the right side is when I use the formula above to convert to datetime value. No sure why it would be different?
error
0
 
mlmccCommented:
I should have said to display the answer in 24hour format so that 0 hours shows as 0 hours rather than 12

What does the date field have?

mlmcc
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
srodgers45Author Commented:
The format for the date is 01-01-2011
0
 
mlmccCommented:
Is the date field a date or string?

mlmcc
0
 
srodgers45Author Commented:
Sorry, a string
0
 
mlmccCommented:
Try

DTSToDateTime({FDC_Trips.atpsdate} &  " "  & {FDC_Trips.atpstime})

mlmcc

0
 
mlmccCommented:
If you need the date the function expects dates as 2011-01-01

mlmcc
0
 
srodgers45Author Commented:
That worked. Thanks for the expert help.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now