In
this article I am going to explain how to get date and time from current date
in Sql server.
In
the previous article have explained how to display today's date, time andtimezone using AngularJs, how to count number of words and character using sqlserver and how to set auto incremented, auto generated alphanumeric unique IDin sql server.
Implementation:
Here
is the query:
declare @date as datetime = getdate()
Select [Current date] =
@date )--Current date
-–Output 2016-11-13 21:28:39.080
Select [Date Only]= CONVERT(varchar(10),@date,105)--date only
-–Output 13-11-2016
Select [Time Only]= CONVERT(varchar(10),@date,114)--Time only
--Output 21:28:39:0
OR
SELECT [Time Only]= CONVERT(TIME,@date)--Time only
--Output 21:28:39.0800000
SELECT [Date Only]= CONVERT(DATE,@date)--Time only
--Output 2016-11-13
--Output 2016-11-13
Current date
|
2016-11-13
21:28:39.080
|
Date Only
|
13-11-2016
|
Time Only
|
21:28:39:0
|
0 Comments