Obiettivo
In SQL Server vuoi data e ora correnti senza offset del fuso orario.
Soluzione
Puoi usare CURRENT_TIMESTAMP, GETDATE() oppure SYSDATETIME(). Le prime due hanno precisione inferiore, la terza è più precisa.
SELECT CURRENT_TIMESTAMP;Esempio:
2019-08-14 10:01:06.983Come funziona
CURRENT_TIMESTAMP restituisce un tipo datetime, con al massimo tre cifre frazionarie. GETDATE() si comporta allo stesso modo.
SELECT GETDATE();Più precisione
Se servono più cifre frazionarie, usa SYSDATETIME(), che restituisce un datetime2 con sette cifre:
SELECT SYSDATETIME();Esempio:
2019-08-14 10:01:06.9754163Tutte e tre le funzioni non includono il fuso orario. Se ti serve l’offset, usa SYSUTCDATETIME() per UTC o SYSDATETIMEOFFSET() per un valore con offset.