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!

Add Time field to Date to get DateTime as a number 1

Status
Not open for further replies.

NiteClerk

Technical User
Nov 9, 2009
15
US
I need to find elapsed time between when a work order was requested and completed. Searching Tek-Tips I've found elegant solutions to this. (Thanks everyone!) However due to how our data is stored I need to combine a date field with a time field. A sample of the data is:
{WO.COMPLETIONDATE} data 09/05/2010 00:00:00 and
{WO.COMPLETIONTIME} data 01/01/1900 17:05:32

I trying to get {WO.COMPLETIONDATE} as 09/05/2010 17:05:32

I can join them as text strings
Code:
Totext({WO.COMPLETIONDATE}, "dd/MM/yy") & Totext({WO.COMPLETIONTIME}, "HH:mm:ss")
but then I have a string and can't perform the math to subtract REQUEST from COMPLETION
Code:
stringvar dt := Totext({WO.COMPLETIONDATE}, "dd/MM/yy") & Totext({WO.COMPLETIONTIME}, "HH:mm:ss");
numbervar tsecs := datediff("s",{WO.REQUESTTIME},CDdateTime(dt)); // number of seconds between the dates
numbervar ndays := truncate(tsecs/86400); // divide by the seconds in a day
tsecs := remainder(tsecs,86400); // find the left over seconds
numbervar nhours := truncate(tsecs/3600); // divide by the seconds in an hour
// Code goes on to get minutes and seconds.

I'm getting a message that Crystal expects a number, datetime or boolian at the CDdateTime(dt)) point.

Thanks for any assistance. ~Bob~
 
Change the first two lines to:

datetimevar dt := datetime(date({WO.COMPLETIONDATE}),time({WO.COMPLETIONTIME}));
numbervar tsecs := datediff("s",{WO.REQUESTTIME},dt);

This assumes that {WO.REQUESTTIME} is a datetime also.

-LB
 
Thanks LB ! Also thanks to everyone who post solutions here and the folks who hosts Tek-Tips. I frequently find solutions to my report problems when searching Tek-Tips. Plus I learn a lot from reading the solutions to other people's posts. I do appreciate all you experts who keep helping out. ~Bob~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top