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

CDate()

Status
Not open for further replies.

westiex2

Programmer
Sep 8, 1999
2
US
Hello - I've got a string field that is a date (example 2001-08-01)

Could you give an example of the syntax to use CDate function.

Do I use this as a formula?

Sorry so basic.

DC
 
Cdate is a visual basic command as far as I know. Crystal reports (8.5) has a date(yyyy,mm,dd) function you can use in the formula. and a date(DateTime) function. you'll have to play with both of them to get it to work correctly, I'm not sure what date/time formats the 2nd one takes, and for the first one, you'll have to parse the text field appart.
 
This is straight out of MSDN:

CDate Function Example
This example uses the CDate function to convert a string to a Date. In general, hard-coding dates and times as strings (as shown in this example) is not recommended. Use date literals and time literals, such as #2/12/1969# and #4:45:23 PM#, instead.

Dim MyDate, MyShortDate, MyTime, MyShortTime
MyDate = "February 12, 1969" ' Define date.
MyShortDate = CDate(MyDate) ' Convert to Date data type.

MyTime = "4:35:47 PM" ' Define time.
MyShortTime = CDate(MyTime) ' Convert to Date data type.

 
In Crystal 8.5, you can type in a string literal (such as you gave in your example) as follows:

CDate ("2001-08-01")

and it will return 08/01/2001. Obviously, it would be better if you didn't have to hardcode the date or use date literals as Olichap suggested. Hope this answers your question.
 
Wasn't suggesting anything Chopstik, just supplying the requested info.
 
Sorry, Olichap. Meant to say that it would be better if he used the info in your post as opposed to hard-coding data.
 
Here is the way I like to do it:

Date(val({table.field}[1 to 4]),val({table.field}[6 to 7]),
val({table.field}[9 to 10]))

Crystal Reports training, consulting, books, training material and on-site support. Scheduled traing in 8 cities.
800-783-2269
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top