If you are only interested in a chain with the current date / time, you can do it like this:
The interesting thing here is that you can use any of the representations of FORMAT
to give the style you want to the exit.
--Salida:
hora_actual
2018-05-25 15:55:40
-
SQL Prev 2012:
SELECT CONVERT(VARCHAR(19), CURRENT_TIMESTAMP, 120) hora_actual;
--Salida:
hora_actual
2018-05-25 15:55:40
NOTE: CURRENT_TIMESTAMP
does not actually throw a date object, if you want to work with date object as such you should use SYSDATETIME()
or GETDATE()
.
For example:
SELECT FORMAT(SYSDATETIME(), 'yyyy-MM-dd HH:mm:ss') hora_actual; -- 2012+
SELECT CONVERT(VARCHAR(19), SYSDATETIME(), 120) hora_actual; -- 2012-
SELECT FORMAT(GETDATE(), 'yyyy-MM-dd HH:mm:ss') hora_actual; -- 2012+
SELECT CONVERT(VARCHAR(19), GETDATE(), 120) hora_actual; -- 2012-
The departures will always be the same.