Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

My Experiments with SQLServer
Browse by Tags · View All
SQLServer 126
SQLServer 2008 R2 91
SQLServer 2008 86
SQLServer 2005 82
SQL 60
Database 59
Sql And Me 57
Tips & Tricks 28
SQL Server 27
SQL FAQ 26

Archive · View All
May 2011 25
June 2011 21
July 2011 21
August 2011 19
April 2011 16
January 2013 4
May 2012 3
April 2012 3
October 2011 3
February 2013 2

Vishal Gajjar's Blog

How to get difference between two dates – TSQL

May 22 2011 7:12AM by Vishal Gajjar   

To calculate the difference between two dates, you can use DATEDIFF() function. The DATEDIFF() function returns the number of days/month/years and time between two dates.

Syntax:

DATEDIFF (date part, start date, end date)

For example, to calculate time left till Independence Day, you can use:

-- © 2011 – Vishal (http://SqlAndMe.com)
 
DECLARE     @Today      DATETIME = GETDATE()
DECLARE     @IDay       DATETIME = '2011-08-15 08:30:00'
 
SELECT DATEDIFF(DAY, @Today, @IDay),      'Days Left'
UNION ALL
SELECT DATEDIFF(MONTH, @Today, @IDay),    'Months Left'
UNION ALL
SELECT DATEDIFF(YEAR, @Today, @IDay),     'Years Left'
UNION ALL
SELECT DATEDIFF(QUARTER, @Today, @IDay),  'Quarters Left'
UNION ALL
SELECT DATEDIFF(HOUR, @Today, @IDay),     'Hours Left'
UNION ALL
SELECT DATEDIFF(MINUTE, @Today, @IDay),   'Minutes Left'
UNION ALL
SELECT DATEDIFF(SECOND, @Today, @IDay),   'Seconds Left'

Result Set:

———–        ————-
86          Days Left
3           Months Left
0           Years Left
1           Quarters Left
2052        Hours Left
123122      Minutes Left
7387278     Seconds Left
 
(7 row(s) affected)

To see all possible values for datepart check BOL.

Hope This Helps! Cheers!


Republished from Sql&Me [31 clicks].  Read the original version here [32134 clicks].

Vishal Gajjar
46 · 4% · 1276
0
Liked
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]