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

Using a String Time Field in a Calculation

Status
Not open for further replies.

PurpleTom

Technical User
Aug 27, 2003
2
CA
I am using Crystal 8.5 with a Pervasive DB. The file I an accessing contains two field called called StartTime and EndTime. Both fields store the value as strings.

I want to use those fields to calculate the total hours an employee worked in a day. (eg if the start time is 0745 and the end time is 1600, the report should calculate 8 hours and 15 mins.)

I have been able to convert the string to a number but that's as far as I have been able to get.

Any help would be greatly appreciated from this Crystal Programming Newbie.

Thanks
 
Assuming your values are strings, you can convert them to real times by using;

TimeValue(ToNumber(Left({Table.Start_Time},2)),ToNumber(Right({Table.Start_Time},2)),0)

Where Table.Start_Time always contained a numeric string e.g. "0745". Do the same for the end time.

Then you could use the DateDiff function to establish the difference between the two.

Peter Shirley
 
A neater way to create a true time value from a string 0745 would be:

time(picture("0745","xx:xx"))

To get the display your after use:

Local TimeVar Start := Time(Picture("0745","xx:xx"));
Local TimeVar End := Time(Picture("1600","xx:xx"));
Local Numbervar Minutes := (End - Start)/60;
Local Numbervar Hours := ((End - Start)/60)/60;

Totext(Int(Hours),0,"")&" Hour(s) "&Totext(Minutes-Int(Hours)*60,0,"")&" Minute(s)"




Reebo
Scotland (Sunny with a Smile)
 
A neater way to create a true time value from a string 0745 would be:

time(picture("0745","xx:xx"))

To get the display your after use:

Local TimeVar Start := Time(Picture("0745","xx:xx"));
Local TimeVar End := Time(Picture("1600","xx:xx"));
Local Numbervar Minutes := (End - Start)/60;
Local Numbervar Hours := ((End - Start)/60)/60;

Totext(Int(Hours),0,"")&" Hour(s) "&Totext(Minutes-Int(Hours)*60,0,"")&" Minute(s)"

Change the items in bold to your fields.



Reebo
Scotland (Sunny with a Smile)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top