SQL has a DateName function, however it takes a datetime as a parameter, not a number
Usage is as follows
DATENAME(month,date) returns Month Name
Sample Query
SELECT DATENAME(month, GETDATE()) AS ‘Month Name’
——————————
Output: January
Suppose i want to print previous month date, how can i do. There is a quick way.
print(DATENAME(month,DATEADD (month , -1, getdate() )))
The dateadd DATEADD (month , -1, getdate() ) function deducts one month from current date, then i will use DateName() function to print the previous month date.
Current Month: January, so
Output: December
so that’s all for now.. it’s simple for you, just i thought of posting may be useful for somebody..
Enjoy coding..
Discover more from Cloud Distilled ~ Nithin Mohan
Subscribe to get the latest posts sent to your email.
[…] Here I am explaining about some of the commonly used Date Functions. in my previous one article i have already explained about DATENAME() function which i am not going to explain again. You can find that article here DateName() in SQL Server. […]