Solved

# Time Conversion

Posted on 2011-02-12
337 Views
Last Modified: 2012-05-11
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
Question by:srodgers45
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions
• 5
• 4
9 Comments

LVL 100

Expert Comment

ID: 34880489
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);
``````
0

Author Comment

ID: 34881014
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?
0

LVL 100

Expert Comment

ID: 34881108
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

Author Comment

ID: 34881125
The format for the date is 01-01-2011
0

LVL 100

Expert Comment

ID: 34881296
Is the date field a date or string?

mlmcc
0

Author Comment

ID: 34881333
Sorry, a string
0

LVL 100

Accepted Solution

mlmcc earned 500 total points
ID: 34881372
Try

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

mlmcc

0

LVL 100

Expert Comment

ID: 34881377
If you need the date the function expects dates as 2011-01-01

mlmcc
0

Author Closing Comment

ID: 34883329
That worked. Thanks for the expert help.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

Title # Comments Views Activity
Crystal Reports Format Field with Dashes 6 71
Help with a Crystal Report Formula 8 57
display n/a in column 2 45
Cant attach a pdf to a crystal report 3 45
Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Six Sigma Control Plans
###### Suggested Courses
Course of the Month2 days, 20 hours left to enroll

#### 752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.