Sql server: get Date, Time, Day, Month, Year, Hour, Minute and Second from date - Free Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server,WCF,Entity framework snippets and tutorial

Sql server: get Date, Time, Day, Month, Year, Hour, Minute and Second from date

In this article I am going to explain how to get Date, Time, Day, Month, Year, Hour, Minute and Second from date in Sql server.


Implementation:
Here is the query:

declare @date as datetime = getdate()
select [Today's date]= @date --2016-11-13 22:22:36.057
select [date Only] =CONVERT(varchar(10),@date,106) --13 Nov 201
select [Time only] =CONVERT(varchar(10),@date,108) --24 hour 22:22:36
Select [Time Only]=RIGHT(CONVERT(varchar(20), @date, 100), 7) --12 hour
Select [Day] =DATEPART(DAY,@date) --13
Select [Month] =DATEPART(MONTH,@date) --11
Select [year] =DATEPART(YEAR,@date) --2016
Select [Hour] =DATEPART(HOUR,@date) --22
Select [Minute] =DATEPART(MINUTE,@date) --22
Select [Second] =DATEPART(SECOND,@date) --44
Select [Milli Second] =DATEPART(MILLISECOND,@date) --943

OUTPUT:

get Date, Time, Day, Month, Year, Hour, Minute and Second from date




What do you think about this article?

If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.

Share this

Share on FacebookTweet on TwitterPlus on Google+


EmoticonEmoticon