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

Converting text to date 2

Status
Not open for further replies.

Bennie47250

Programmer
Nov 8, 2001
515
US
Using Crystal reports version 14.0.4.738 RTM
Reporting on a MS SQL table

Our CRM package stores dates in a text field as 2016-03-30.

They had provided a custom DLL to convert the field to a real date field to allow using the Crystal date functions such as LastFullWeek, MonthToDate, CurrentDate, CurrentDate -1. The DLL was updated each time the CRM provider provided a upgrade to Crystal. However the last DLL I have was written for Crystal 7.0.

I'm having some issues with Crystal 14 using the DLL and would like to change the formulas to use standard Crystal 14 functions.

What functions would I want to use to convert the text 2016-03-30 to a real date?
What function would I want to use to convert a real date to text that looks like 2016-03-30?

Thanks
Bennie
 
This formula should work:

numbervar yr := val(left({your text-date field},4));
numbervar mt := val(mid({your text-date field},6,2));
numbervar dy := val(right({your text-date field},2));
date(yr,mt,dy)


This will turn the text field into a date field.
 
Date("2016-03-30") turns the string into a real date so if your field is called MyDate then try
Date({table.MyDate}) and see if that works

Gordon BOCP
Crystalize
 
Thanks all. I found that Crystal has a built in Type Conversion function CDate (number or string) built into it and it converted the field just fine.
 
Crystal reports has several functions that go by more than one name.
So CurrentDate and Today for example.
And CDate and Date are another example.

Gordon BOCP
Crystalize
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top