Selenium WebDriver Java Framework Course Limited Time Offer for $20

Selenium WebDriver Java Framework Course Limited Time Offer for $20

 

Print

Date Time Operations in SQL Server

In SQL Statement, we can use GETDATE() and DATEDIFF() to do calculation for Date Time. 

 

Use AdventureWorks2008
Go

--Get Current Date
select GETDATE() as 'current_time'
--Get Data Difference in Day
Select DATEDIFF(DAY,'2014-7-10',GETDATE()) as Total_Days
--Get Data Difference in Month
Select DATEDIFF(MONTH,'2014-6-10',GETDATE()) as Total_Month
--Get Data Difference in Year
Select DATEDIFF(YEAR,'2012-6-10',GETDATE()) as Total_Year

SQL Result

current_time
-----------------------
2014-07-27 19:28:18.027

(1 row(s) affected)

Total_Days
-----------
17

(1 row(s) affected)

Total_Month
-----------
1

(1 row(s) affected)

Total_Year
-----------
2

(1 row(s) affected)