Skip to main content

Posts

Showing posts with the label DATEDIFF

How to convert date difference into years in SQL

Add below in your SQL query and it will get date difference and convert into years: (DATEDIFF(MONTH,TABLE.BIRTH_DT,CURRENT_TIMESTAMP)/12) The DATEDIFF() function returns the difference between two dates. DATEDIFF(Interval, date_1, date_2) The CURRENT_TIMESTAMP() function returns the current date and time. SELECT CURRENT_TIMESTAMP()

How to convert date difference into days in SQL

Add below in your SQL query and it will subtract date column from today's date and convert into days: CONVERT(INT, GETDATE() - TABLE.CREATED_DATE) AS 'Age' OR DATEDIFF(DAY,TABLE.CREATED,GETDATE()) The GETDATE() function returns the current database system date and time. SELECT GETDATE() The CONVERT() function converts a value (of any type) into a specified datatype. CONVERT(data_type), expression/ value) SELECT CONVERT(INT, 1.1) The DATEDIFF() function returns the difference between two dates. DATEDIFF(Interval, date_1, date_2)