Print Page | Close Window

convert string to date

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=22080
Printed Date: 02 May 2024 at 6:47pm


Topic: convert string to date
Posted By: Kitty1
Subject: convert string to date
Date Posted: 09 Sep 2016 at 4:50am
hi, is there a way to convert a string (2016099) for example, into a date field, that i could use to select certain records for my report ?



Replies:
Posted By: kevlray
Date Posted: 09 Sep 2016 at 5:27am
Maybe, what would the value 2016099 convert to as a date?  You probably would use the Date function with the left, mid and right functions (and Val to convert the different parts to numbers).


Posted By: Kitty1
Date Posted: 09 Sep 2016 at 5:44am
thank you, would you be able to show me the formula i would use ?   i don't just need it to print the date in a different format, i need it to be a date field and not a string field.


Posted By: kevlray
Date Posted: 09 Sep 2016 at 7:38am
That I why I asked what 2016099 would convert to as a date.  Normally a string field that represents a date is either six or eight characters long, not seven.  


Posted By: Kitty1
Date Posted: 09 Sep 2016 at 7:40am
I am so sorry. that should have read 20160909



Posted By: kevlray
Date Posted: 09 Sep 2016 at 7:57am
Okay assuming that 2016 is the year and the first 09 is the month.  Then this should work (provided there are no nulls).

date(val(left({stringfield},4)),val(mid({stringfield},5,2)), val(right({stringfield},2)))


Posted By: Kitty1
Date Posted: 09 Sep 2016 at 8:16am
thank you so much, that worked!!! have a great weekend!



Print Page | Close Window