Print Page | Close Window

CDate Problem!!!

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=5259
Printed Date: 03 May 2024 at 5:04pm


Topic: CDate Problem!!!
Posted By: santy2906
Subject: CDate Problem!!!
Date Posted: 19 Jan 2009 at 9:42am

Hi All,

Need your help in solving this strange problem of crystal report's date conversion.
 
Environment: C# .NET 2003, Crystal XI and SQL Server 2005.
 
Report is generated programmatically using a blog stored in the database.
We set RecordSelectionFormula that is a member of CRAXDRT.Report class. The string we set is - IN [CDate(15/01/2008) To CDate(28/01/2008)] and later call it's Export function to generate the report but this function fails and throws an error - Month should be between 1 and 12. Everything in our system is set to dd/MM/yyyy format even the SQL Server.
 
Am I missing something here i.e. we need to set the date time format while generating the report programmatically in .NET? if yes, what's the code to do that?? or there is a bug Im not aware of in Crystal XI?
 
Really need some1 to help me out here, it's pretty urgent!!!
 
Thanks in advance,
Santy



Replies:
Posted By: DBlank
Date Posted: 19 Jan 2009 at 10:45am
Try
IN [CDate(15/01/2008,"dd/MM/yyyy") To CDate(28/01/2008,"dd/MM/yyyy")]


Posted By: santy2906
Date Posted: 19 Jan 2009 at 12:28pm
Hi DBlank,
 
I have done exactly the same way (as you mentioned) with double quotes. It's just that I forgot to add them here in the text.
 
Oops!!! I didn't see your post properly.... CDate don't take string format as the second parameter if I am not wrong but still I will try...
 
I mostly feel it's a crystal report problem as it is by default taking MM/dd/yyyy format or may be I am missing something - any property setting (to Report object) to take window's date format.
 
Thanks anyways for your time.
 
Santy


Posted By: DBlank
Date Posted: 19 Jan 2009 at 1:19pm
I can't access my crystal today but I beleive youy can set your date type defaults in Report Setup. Did you check there?


Posted By: Savan
Date Posted: 19 Jan 2009 at 11:11pm
i think this also can be used
IN [date(2008,01,15) To Date(2008,01,28)]

-------------
Thanks
Savan


Posted By: DBlank
Date Posted: 20 Jan 2009 at 7:25am
Hi Santy,
Sorry about the incorrect info before. Vacation has a way of turning the brain off temporarily Ermm
I looked and did not see any general setting for putting a date into earopean format without using month names.
You can go into custom settings and try to set it there but in testing I did not have any luck with that altering my field displays and I am not sure if that will address it at the join level.
IN [Date(#15/01/2008#) To Date(#28/01/2008#)] should work but it displays back as M/d/yyyy so I am not sure how that will mess up the rest of your report.
Sorry I could not be of more help...seems like there should be a general setting to address such a standard format...


Posted By: santy2906
Date Posted: 21 Jan 2009 at 2:44pm
Savan,
 
Thanks 4 replying but I tried that also but it's throwing the same error message.
 
Santy


Posted By: santy2906
Date Posted: 21 Jan 2009 at 2:49pm
Hi DBlank,
 
Actually, if you enclose date string in #s for CDate, by default it uses MM/dd/yyyy format but I need dd/MM/yyyy format so your solution IN [Date(#15/01/2008#) To Date(#28/01/2008#)]  won't work here bcoz it will intepret 15 as the month.
 
Source: Crystal Reports for CDate
 
Thanks,
Santy


Posted By: DBlank
Date Posted: 21 Jan 2009 at 7:18pm
Hmmmm,
I added the Date(#15/01/2008#) in a formula and it acccepted fine but displays it as "1/15/2008" when i put the formula in the report.
Just as a test did you try and swap the
IN [CDate(15/01/2008) To CDate(28/01/2008)]
to
IN [CDate(01/15/2008) To CDate(01/28/2008)]
to validate this is exactly what it is choking on and not another date field somwhere else?



Print Page | Close Window