?
Solved

Crystal Report Convert String to Date

Posted on 2012-04-08
7
Medium Priority
?
1,725 Views
Last Modified: 2012-04-08
I declared a column in SQL table to varchar and the parameter in Crystal Report (asp) to Date.
Parameter1 is called DateFrom (Date)
Parameter 2 is called DateTo (Date)
I also created a formula in the Record:

ToText({Table.Date},"MM/dd/yyyy") >= {?DateFrom}
 and
ToText({Table.Date},"MM/dd/yyyy")<= {?DateTo}

I tried to convert the Table.Date to Date format and then use the parameter but it gives me an error like: "A string is needed"
The main reason I did this was that I did not want to use the DateTimeFormat in SQL and ONLY WANTED TO HAVE THE MM/DD/YYYY instead of THE Date and Time.

PLEASE HELP. This is driving me crazy.
FYI: I am using ASP.NET C# and this is my first asp, Crystal project so please be clear in your comments.
0
Comment
Question by:pauledwardian
7 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 37821064
You parameters and the values you are comparing them to must be th same data type.  You cannot have one as text and the other as date as in your post.

But since you are using varchar in your database aren't  the values already 'text'?  What datatype does Crystal see the date field as ?

If the dates are regarded by Crystal as text,  then unless they are already in a format that can be compared you will have to do two levels of conversion.  

I think we need to see some sample ' date ' values from the database.
0
 
LVL 20

Assisted Solution

by:BuggyCoder
BuggyCoder earned 664 total points
ID: 37821103
convert specific sections and form date:-
CDate (
(ToNumber ({TextDateField} [1 to 4])),
(ToNumber ({TextDateField} [5 to 6])),
(ToNumber ({TextDateField} [7 to 8]))
)

refer here:
http://www.forumtopics.com/busobj/viewtopic.php?t=171929&sid=7c117f8d8872d20afe1f5a95a66bf8a0
0
 
LVL 101

Assisted Solution

by:mlmcc
mlmcc earned 1336 total points
ID: 37821290
Nice try buggy but the format of his field is mm/dd/yyyy

Try it this way

CDate (
(ToNumber ({TextDateField} [5 to 8])),
(ToNumber ({TextDateField} [3 to 4])),
(ToNumber ({TextDateField} [1 to 2]))
)

mlmcc
0
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 

Author Comment

by:pauledwardian
ID: 37821777
I got this error: Please look at the attachment. I also changed my SQL dateformat to TEXT instead of Varchar:
This also includes a screenshot of the setting I used to format thew parameters:
Crystal Settings
0
 

Author Comment

by:pauledwardian
ID: 37821900
Never mind. I didnt verify the database after making the changes that was why it was giving me the error.
Now a differant question:
On the Report Preview in visual studio I can see the Refresh button on the report but when I compile the application and run the report it does not exit there.
How can I add that feature on the report OR how can I add a button in my C# page to Refresh the report?

Paul
0
 
LVL 101

Accepted Solution

by:
mlmcc earned 1336 total points
ID: 37821951
I have n't used that viewer but check the properties.  Each button usually has an ENABLE property

mlmcc
0
 

Author Closing Comment

by:pauledwardian
ID: 37822234
Thanks!
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month16 days, 7 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question