Skip to main content

Posts

Showing posts with the label sql datediff date format

SQL Server - Data Types

Main categories of SQL Server Data Types, 1.       Numeric  a.       Exact Numeric  b.       Approximate Numeric  2.       Date and Time  3.       Character String  a.       Non-Unicode Character String  b.       Unicode Character String  4.       Binary  5.       Others The following detail as given below, DATA TYPES SYNTAX DESC Integer            INTEGER          It is integer data type and used to specify an integer value. Smallint SMALLINT It is small lint data type and used to specify small integer value. Numeric NUMERIC(X, Y) It ...

SQL Server DateDiff - Date Format

The DATEDIFF function is use to get the differences in days, hours, minutes, seconds etc. and  It is returns the time between two dates. The DATEDIFF function can be used from above version of SQL Server 2005. --Syntax DATEDIFF(DATE_PART, START_DATE, END_DATE) --Types of, SELECT DATEDIFF( DAY , GETDATE(), GETDATE() + 1 ) AS DAY_DIFFERENCE SELECT DATEDIFF(WEEK, GETDATE(), GETDATE() + 1 ) AS WEEK_DIFFERENCE SELECT DATEDIFF(HOUR, GETDATE(), GETDATE() + 1 ) AS HOUR_DIFFERENCE SELECT DATEDIFF( MINUTE , GETDATE(), GETDATE() + 1 ) AS MINUTE_DIFFERENCE SELECT DATEDIFF( SECOND , GETDATE(), GETDATE() + 1 ) AS SECOND_DIFFERENCE -- Example as, SELECT DATEDIFF( YEAR , '2015/04/28' , '2016/04/28' ); --RESULT is: 1 SELECT DATEDIFF(YYYY, '2015/04/28' , '2016/04/28' ); --RESULT is: 1 SELECT DATEDIFF(YY, '2015/04/28' , '2016/04/28' ); --RESULT is: 1 SELECT DATEDIFF( MONTH , '2015/01/01' , '2016/04...