November 18, 2009 at 5:08 pm
I have a stored proc that accepts input parameters from an asp page. The value entered for an issueDate textbox on the page is a in the format of 'yyyymmdd''. This value is passed to the stored proc as VarChar(8), but I need to convert the value of this input parameter to datetime to insert it into a table. When I use:
Convert(DateTime, @issueDate, 112),
I get
1900 00 00 00:00 inserted into the table.
What is the solution?
Thank you
November 18, 2009 at 5:30 pm
Try this
SELECT CAST(@issueDate AS DATETIME)
Blog -- LearnSQLWithBru
Join on Facebook Page Facebook.comLearnSQLWithBru
Twitter -- BruMedishetty
November 18, 2009 at 5:47 pm
I don't get the same problem. When that date pops up, it could be due to an invalid date that has been input.
declare @issuedate varchar(8)
Set @issuedate = '20091118'
select Convert(DateTime, @issueDate, 112),CAST(@issueDate AS DATETIME)
I tested with both cast and convert to verify and both return the same value. Even If I change the date to '091118' I still get the correct date.
Here is an article with some date format info. Maybe a locale is set differently than expected.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
November 18, 2009 at 6:08 pm
Thanks for the prompt reply. I will test the Cast, Convert function did not work.
November 18, 2009 at 6:09 pm
Thanks. I will try it Convert function did not work.
November 19, 2009 at 6:39 am
Actually Cast(@issuedate As DateTime) worked.
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply