• Home
  • About
SQiLler

Tag Archives: date and time difference

How to get Date and Time Difference

Posted on July 22, 2014 by Hiram Romero

Do you want to know how many days are between 2 given dates?

Or how many months, weeks, hours, minutes or seconds?

Easy peasy!

Just check the following examples:

SELECT DATEDIFF(MONTH, GETDATE(), GETDATE() + 1) AS MonthDiff
SELECT DATEDIFF(WEEK, GETDATE(), GETDATE() + 1) AS WeekDiff
SELECT DATEDIFF(DAY, GETDATE(), GETDATE() + 1) AS DayDiff 
SELECT DATEDIFF(HOUR, GETDATE(), GETDATE() + 1) AS HourDiff
SELECT DATEDIFF(MINUTE, GETDATE(), GETDATE() + 1) AS MinuteDiff
SELECT DATEDIFF(SECOND, GETDATE(), GETDATE() + 1) AS SecondDiff

 

Syntax: DATEDIFF ( datepart , startdate , enddate )

SQL DateDiff

SQL DateDiff


Posted in SQL | Tags: date and time difference, MSSQL, sql, sqlserver, TSQL | 3 Comments |

Stack Overflow

profile for sqiller on Stack Exchange, a network of free, community-driven Q&A sites

Recent Posts

  • English dictionary with synonyms
  • Create your own SQL log
  • Drop table if exists
  • Replace a value in all tables
  • Share temp tables to other sessions
Follow on Bloglovin

Pages

  • About

Archives

  • June 2015
  • August 2014
  • July 2014

Categories

  • SQL (23)

WordPress

  • Register
  • Log in
  • WordPress
CyberChimps

CyberChimps

© SQiLler