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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Getting May 1st of Previous Year

Author  Topic 

MCusuma1
Starting Member

13 Posts

Posted - 2013-09-19 : 10:15:19
Hello, I have been trying to figure this out. I need to get May 1st of the previous year. I have the following but it is not working:

SELECT DATEFROMPARTS(DATEADD(yy, -1, GETDATE()), 5, 01)

I get the error message "Msg 257, Level 16, State 3, Line 1
Implicit conversion from data type datetime to int is not allowed. Use the CONVERT function to run this query."

I'd appreciate any help.


James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-09-19 : 10:32:00
Use DATEFROMPARTS(year(getdate())-1,5,1)
Go to Top of Page

MCusuma1
Starting Member

13 Posts

Posted - 2013-09-19 : 10:50:57
quote:
Originally posted by James K

Use DATEFROMPARTS(year(getdate())-1,5,1)



This worked great thanks!
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-09-19 : 11:03:28
You are very welcome - glad to help.
Go to Top of Page

sigmas
Posting Yak Master

172 Posts

Posted - 2013-09-19 : 11:17:38
quote:
Originally posted by MCusuma1

Hello, I have been trying to figure this out. I need to get May 1st of the previous year. I have the following but it is not working:

SELECT DATEFROMPARTS(datepart(yy,DATEADD(yy, -1, GETDATE())), 5, 01)




Go to Top of Page
   

- Advertisement -