How to get date and time from current date in Sql server

In this article I am going to explain how to get date and time from current date in 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

Current date
2016-11-13 21:28:39.080

Date Only
13-11-2016

Time Only
21:28:39:0

  

Post a Comment

0 Comments