Home > Enterprise >  Microsoft SQL Server 2016 Date as Numerical Representation
Microsoft SQL Server 2016 Date as Numerical Representation

Time:08-10

Does anyone know if there is a way to get a number representation of a date, the same way DB2 does theirs?

https://www.ibm.com/docs/pl/db2-for-zos/11?topic=functions-days

SELECT 
POSTING_DATE,
DAYS(POSTING_DATE) AS NUMBER_REPRESENTATIOn
FROM core.env

enter image description here

I've been searching but, cannot seem to find a solution. Thanks!

CodePudding user response:

The documentation seemed pretty clear, you just have to translate the formula to use T-SQL syntax (where we measure the number of days between two dates using DATEDIFF):

DECLARE @d date = '20220808';

SELECT DATEDIFF(DAY, '00010101', @d)   1;

Result:

738,375

  • Related