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.
In the previous article have explained how to read JSON or txt file data anddisplay using AngularJs, how to generate and download Json file in mvc and howto create multiselect dropdown with checkbox using Bootstrap multiselect Jqueryplugin.
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
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.