.NET/C#
  • ASP.NET Core Overview
  • ASP.NET Core API tutorial
    • How to create ASP.NET Core C# API tutorial
      • launchSettings
      • Install swagger
        • Swagger best practices
      • Run the app
      • Fix CORS problem
      • Add AutoMapper
      • Add JWT reference
      • Add .gitignore
      • Basic structure & EF Core
      • AddSingleton
    • Loading Related Entities
  • Unit test controller logic in ASP.NET Core
    • Unit testing controllers
  • .NET Q&A
    • dotnet try
    • LINQ
      • LINQ Query Syntax
      • Lambda Expression
      • Standard Query Operators
  • .NET C# Interview questions
    • C# - .NET interview questions and answers [Part 1]
    • C# - .NET interview questions and answers [Part 2]
    • C# Interview questions [Part 3] General questions
  • C#
    • Object-Oriented Programming (Principles)
      • N-tier architecture style
      • Command and Query Responsibility Segregation (CQRS) pattern
      • Project architecture
    • C# Advanced review
      • Implicit typing
      • Generics
      • Attributes
      • Reflection
      • Delegates
      • Anonymous Methods and Lambda Expressions
      • Events
      • Ref vs Out
      • Task
        • TaskFactory Class
  • MySQL
    • MySQL Lerning
      • SELECT
      • ORDER BY
      • WHERE
      • DISTINCT
      • IN
      • BETWEEN
      • Join
      • INNER JOIN
      • LEFT JOIN
      • RIGHT JOIN
      • GROUP BY
      • Subquery
      • UNION
    • Stored Procedures
      • CREATE PROCEDURE
  • Versioning API, MongoDB and ci-cd
    • Create a web API with ASP.NET Core and MongoDB
    • REST API versioning with ASP.NET Core
    • Design a CI/CD pipeline using Azure DevOps
      • Create a CI/CD pipeline for GitHub repo using Azure DevOps Starter
  • TFS & TFCV
    • What is Team Foundation Version Control
      • Develop and share your code in TFVC using Visual Studio
      • Suspend your work and manage your shelvesets
    • Newtonsoft Json.NET
      • Serializing and Deserializing JSON
  • MS-SQL
    • Quick tutorial
      • Add new column to a table
      • LEFT/RIGHT Reverse operator
      • Dates (Transact-SQL)
      • CAST and CONVERT (Transact-SQL)
      • Types of JOIN
      • Our first Left Outer Join
      • CROSS JOIN
Powered by GitBook
On this page
  • DATEDIFF (Transact-SQL)
  • DATEPART (Transact-SQL)

Was this helpful?

  1. MS-SQL
  2. Quick tutorial

Dates (Transact-SQL)

PreviousLEFT/RIGHT Reverse operatorNextCAST and CONVERT (Transact-SQL)

Last updated 4 years ago

Was this helpful?

DATEDIFF (Transact-SQL)

SELECT *, 
DATEDIFF(MONTH, [first_retail_availability], [discontinued]) AS diff_month
from [dbo].[console_dates] ORDER BY diff_month desc

This function returns the count (as a signed integer value) of the specified datepart boundaries crossed between the specified startdate and enddate.

See for a function that handles larger differences between the startdate and enddate values. See for an overview of all Transact-SQL date and time data types and functions.

DATEDIFF ( datepart , startdate , enddate )  

DATEPART (Transact-SQL)

This function returns an integer representing the specified datepart of the specified date.

select [platform_name], [first_retail_availability]
from [dbo].[console_dates] 
where DATEPART(MONTH, [first_retail_availability]) -11 = 0
select 
	[platform_name], [first_retail_availability]
from 
	[dbo].[console_dates] 
where 
	DATEPART(MONTH, [first_retail_availability]) -12 = 0 OR 
	DATEPART(MONTH, [first_retail_availability]) -11 = 0
DATEDIFF_BIG (Transact-SQL)
Date and Time Data Types and Functions (Transact-SQL)