Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Report Design
Message Icon Topic: Converting String to Date Record Selection Post Reply Post New Topic
Author Message
cant2ny
Newbie
Newbie


Joined: 11 Oct 2011
Online Status: Offline
Posts: 9
Quote cant2ny Replybullet Topic: Converting String to Date Record Selection
    Posted: 28 Feb 2012 at 4:07am
I realized I posted this in the wrong forum yesterday:

Is it possible to convert a string to date during the record selection process? I have a table in my SQL database that is of type VarChar and stores the date as 20120227. I cannot convert this to Date on the DB side due to other factors. Is it possible to convert this VarChar field to a date during Record Selection (to be compared against a Date CR parameter)? There is no formatting needed as that's handled elsewhere, I just need to convert it during record selection to use against the Date CR Parameter.

The only way I can think to do it is to use a SQL command but would like to avoid that since I'll need to do redo the entire report.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 28 Feb 2012 at 4:12am
you can convert it in the select statement itself. Here is an example:
 
date(mid({table.strindate},5,2)+'/'+right({table.strindate},2)+'/'+left({table.strindate},2)) in {?StartDate} to {?Enddate}
IP IP Logged
cant2ny
Newbie
Newbie


Joined: 11 Oct 2011
Online Status: Offline
Posts: 9
Quote cant2ny Replybullet Posted: 28 Feb 2012 at 4:44am
Thanks, however I get a "Bad date Format String" when running a preview. I also adjusted the left({table.strindate},2) to include 4 places. Looks correct in the details section.

Would this be caused by the NULL and "" values in the database?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 28 Feb 2012 at 7:20am
yes.
I assumed you had valid entries in each row.
you can try to add anopther condition that will exclude your '' or null values
 
isdate(mid({table.strindate},5,2)+'/'+right({table.strindate},2)+'/'+left({table.strindate},2)
and
date(mid({table.strindate},5,2)+'/'+right({table.strindate},2)+'/'+left({table.strindate},2)) in {?StartDate} to {?Enddate}
 
IP IP Logged
cant2ny
Newbie
Newbie


Joined: 11 Oct 2011
Online Status: Offline
Posts: 9
Quote cant2ny Replybullet Posted: 28 Feb 2012 at 10:03am
Thanks, I had to scrap trying to salvage the report and ended up having to do the query for the conversion due to other factors.
IP IP Logged
Motib
Newbie
Newbie


Joined: 06 Feb 2013
Location: Pakistan
Online Status: Offline
Posts: 5
Quote Motib Replybullet Posted: 21 Feb 2013 at 5:50pm
hi all,
i have a varchar type in sql and it is stored like 22/1/2012. but i want to get opening balance of qty....... if i write "If {DDate} < {?From Date} then "Qty"" but it will showing me 0.
plz help me is this write condition or not.
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.