Print Page | Close Window

Failure to convert datetime from character Error

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=4822
Printed Date: 06 May 2024 at 12:11am


Topic: Failure to convert datetime from character Error
Posted By: petronas
Subject: Failure to convert datetime from character Error
Date Posted: 17 Nov 2008 at 11:30am

Hi,

I have the below SQL query in Creports. It is throwing an error " Conversion failed when converting datetime from character string".

Declare @Get_Date datetime, @StartDate Varchar(30)

select  @StartDate  = '{?StartDate}'

Select @Get_Date = convert(varchar ,month(Getdate()) )+ '/01/' +convert(varchar, year(Getdate()))
Select @Get_Date = dateadd(m,datediff(m,0, convert(datetime,@StartDate) ),0)

I think I am missing something. Any ideas?

Thanks,
Petronas




Replies:
Posted By: lockwelle
Date Posted: 18 Nov 2008 at 6:26am
Where are you doing this? And the first @Get_Date isn't used...And the 2nd @Get_Date seems to be getting the starting date of the month from 0. 
But what might be the cause is the first @Get_Date, it is a string...add a CONVERT(DATETIME, (convert(varchar....
 
That should get you around the error, I think
 



Print Page | Close Window