Skip to main content

Posts

Showing posts with the label CONVERT

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)