Display the current date each time a command is executed

1

Is there a command or function that shows the date when a command is executed?

Use SQL Developer, and for example if I run:

select sysdate from dual 

Set the system date, and I want the date to be with hours, minutes and seconds. How could I do that?

    
asked by m3nt0r1337 06.10.2016 в 19:04
source

2 answers

2

If you go to the Oracle documentation for SYSDATE , includes an example in which the output of said function is formatted to show date and time with hours, minutes and seconds as you want:

SELECT TO_CHAR
    (SYSDATE, 'MM-DD-YYYY HH24:MI:SS') "NOW"
     FROM DUAL;

NOW
-------------------
04-13-2001 09:45:51
    
answered by 06.10.2016 в 23:10
0

If you are using SQL Server, you could use the CONVERT () or CAST

You convert the DateTime type that throws SYSDATETIME () to the varchar type and in the same function CONVERT send as a third parameter the type of format you want to give the date.

For the dd / mm / yyyy format it's 103 For the format hh: mm: ss it is 8 (24h)

If you do not find the format you need, you could play with other T-SQL functions to give the format you need.

SELECT CONVERT(varchar , SYSDATETIME(), 103)+' '+CONVERT(varchar , SYSDATETIME(), 8) AS ActualDate;


DECLARE @FECHA_ACTUAL AS DATETIME2
SET @FECHA_ACTUAL = SYSDATETIME()
SELECT CONVERT(varchar , SYSDATETIME(), 103)+' '+LEFT(RIGHT(CONVERT(varchar , @FECHA_ACTUAL, 9),17), LEN(RIGHT(CONVERT(varchar , @FECHA_ACTUAL, 9),17)) - 10)+RIGHT(RIGHT(CONVERT(varchar , @FECHA_ACTUAL, 9),17),2) AS ActualDate;
    
answered by 06.10.2016 в 22:45