Print Page | Close Window

Convert String to Time

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=1785
Printed Date: 02 May 2024 at 12:06am


Topic: Convert String to Time
Posted By: CVIS Analyst
Subject: Convert String to Time
Date Posted: 28 Nov 2007 at 1:27pm
I am looking for a way to convert  a string which appears as a time 103030 (this is actually 10:30:30) to a time value so that calculations can be preformed on the field. I am using Crystal Reports XI. Thanks for your help.



Replies:
Posted By: BrianBischof
Date Posted: 28 Nov 2007 at 1:53pm
You can use the picture function to map it to the proper date format and then use the CTime() function to convert it to a time data type.
CTime(Picture({field}, "xx:xx:xx"))

Then use the DateAdd() function to do calculations on the field.

I have all the Crystal Reports functions documented with sample code in Chapter 6 of my http://www.amazon.com/exec/obidos/ASIN/0974953601/bischofsystem-20 - Crystal Reports Encyclopedia book


-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>


Posted By: CVIS Analyst
Date Posted: 28 Nov 2007 at 2:04pm
Thank you for your help. When I use the CDate formula as you have suggested the field on the report is blank. Any suggestions?


Posted By: BrianBischof
Date Posted: 28 Nov 2007 at 2:26pm
That should be CTime() instead of CDate(). I originally wrote CDate() in my post but then changed it to CTime() once I read your question a second time. That should get you up and running.


-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>



Print Page | Close Window