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

String to date conversion

Status
Not open for further replies.

jgl99

Technical User
Feb 26, 2002
12
0
0
US
New to Crystal Reports!
I have 2 string fields that represent times, exp. 132021 and 132105, format hhmmss. I want to subtract the 1st value from the 2nd value leaving 44 seconds as a result. I can convert the string to number and get a true substraction but, need a datetime substraction. Any suggestions!
 
Local numberVar timeX1 := cdbl(left('132105',2));
Local numberVar timeX2 := cdbl(mid('132105',3,2));
Local numberVar timeX3 := cdbl(Right ('132105',2 ));

Local numberVar timeX4 := cdbl(left('132021',2));
Local numberVar timeX5 := cdbl(mid('132021',3,2));
Local numberVar timeX6 := cdbl(Right ('132021',2 ));

timevalue(timeX1,timeX2,timeX3) - timevalue(timeX4,timeX5,timeX6)

I believe that this Will return seconds. The number will need to be formatted from there to return hours, minutes, etc.....

Hope this helps...

dLC
 
Quick assuption: The times represented will not exceed 23:59:59

Here is another method to determine the difference in seconds.

stringvar t1:="132021";
stringvar t2:="132105";
timevar t1a:=time(picture(t1,"xx:xx:xx"));
timevar t2a:=time(picture(t2,"xx:xx:xx"));
t2a-t1a


Mike
 
I am using field names not actual string values. Can I replace the string with the field name?

Thanks
 
Yes, replace the string with the database field, assumming the data type is string.

Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
dgilsdorf@trianglepartners.com
 
Sorry,

Field type is number.
 
Try this one then. The first two lines change the number field to a 6 character string field, then uses those strings in the calculation.


stringvar t1:=totext({@timeN1},"000000");
stringvar t2:=totext({@timeN2},"000000");

timevar t1a:=time(picture(t1,"xx:xx:xx"));
timevar t2a:=time(picture(t2,"xx:xx:xx"));

t2a-t1a

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top