Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 String to Date

Author  Topic 

cardullo4321
Starting Member

40 Posts

Posted - 2011-05-20 : 13:55:47
Can anyone tell me how to convert a varchar string '11-Apr' to a datetime in SQL 2005? I do not need the time just the date.

Gregory Cardullo

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-05-20 : 14:05:47
What about the year?
Go to Top of Page

cardullo4321
Starting Member

40 Posts

Posted - 2011-05-20 : 15:46:26
When I download it to excel it has 04/11/2011. I eventually need it to be 04/30/2011 for the last day of the month.

Gregory Cardullo
Go to Top of Page

latch
Yak Posting Veteran

62 Posts

Posted - 2011-05-20 : 16:02:41
try this:

DECLARE @dtDate DATETIME
SET @dtDate = '8/18/2007'
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@dtDate)+1,0))
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-05-20 : 16:05:41
Rob asked something .. is that an answer? If so... sorry i could not understand all all.

Cheers
MIK
Go to Top of Page
   

- Advertisement -