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!

Converting string to date 1

Status
Not open for further replies.

Macho123

Technical User
Oct 20, 2007
62
0
0
US
Hi I am using crystal reports 9, I have a STRING field of this format 2008/08/01 00:00:00, now I want to convert it into a date field and display it as 08/01/2008. I tried date, cdate and other functions on that field but could not get it work. Help would be appreciated.

Thanks...
 
I'm afraid crystal will always take your default date format. To change that for one field in a specific report you need to display it as text:
Code:
totext(date('2008/08/01 10:30:02'),'MM/dd/yyyy')
 
pkra,

try this formula:

numbervar yr := val(left({table.string},4));
numbervar mt := val(mid({table.string},6,2));
numbervar dy := val(mid({table.string},9,2));
Date (yr,mt,dy)

Put this formula on your report and right-click format it to show date as you would like.

Andy
 
My default field in the database itself is a STRING but has date in it.

totext(date(string_field_name),'mm/dd/yyyy')

it says bad date format string type.

To make it clear the STRING field present in the database has the date in it and when that is brought to crysatl though the datatype is string it is automatically converting to date and time as displayed in my first post.

IS there a way to get only date out of it 'mm/dd/yyyy'.

Thanks..
 
pkra,

If the field came over as a string then my formula from above should work. If it came over as a 'Date Time' field, just put it on your report, right-click and format as "03/01/1999" under Style on the 'Date and Time' Tab.

Andy
 
Andymc, your are correct, as I also think you should be able to just right click and set the format.

But in case the string comes as a datetime type and the idea of Andymc doesnt work try
Code:
totext({table.field},'MM/dd/yyyy')
 
Hi Andy,

The formula you gave worked great,

numbervar yr := val(left({table.string},4));
numbervar mt := val(mid({table.string},6,2));
numbervar dy := val(mid({table.string},9,2));
Date (yr,mt,dy)

In my case the date comes as string.

Thanks once again. Beltmanjr thanks for your response too.

pkra
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top