SQL Current Date/Time
Current Date/Time/Timezone
Oracle
Change default date/time display format...
ALTER SESSION SET NLS_DATE_FORMAT='DD-MON-YYYY HH24:MI:SS';
ALTER SESSION SET NLS_TIMESTAMP_FORMAT='DD-MON-YYYY HH24:MI:SS.FF';
ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT='DD-MON-YYYY HH24:MS:SS.FF TZH:TZM';
The client-side NLS_LANG environment variable overrides the defaults for these variables in most cases.The default for NLS_DATE_FORMAT is derived from NLS_TERRITORY.System Date/Time
SELECT SYSDATE
FROM DUAL;
SELECT SYSTIMESTAMP
FROM DUAL;
Current Date/Time
SELECT CURRENT_DATE
FROM DUAL;
SELECT CURRENT_TIMESTAMP
FROM DUAL;
SELECT LOCALTIMESTAMP
FROM DUAL;
For Grid Infrastructure (i.e. database started with crsctl) then TZ is set in...$GRID_HOME/crs/install/s_crsconfig_<nodename>_env.txt
Demonstration (TODO)
CREATE TABLE date_time_demo
(
demo_date DATE,
demo_ts TIMESTAMP;
demo_tstz TIMESTAMP WITH TIME ZONE;
demo_tsltz TIMESTAMP WITH LOCAL TIME ZONE;
);
Diagnostics
All Columns in your data that contain time zone data...
SELECT c.owner,
c.table_name,
c.column_name,
c.data_type
FROM dba_tab_cols c,
dba_objects o
WHERE c.data_type LIKE '%TIME ZONE'
AND c.owner=o.owner
AND c.table_name = o.object_name
AND o.object_type = 'TABLE'
ORDER BY 1,2,3,4
/
For further information on the data dictionary tables in this list see: 402614.1Database Timezone...
SELECT DBTIMEZONE
FROM DUAL;
The Database Time Zone does NOT influence SYSDATE or SYSTIMESTAMP.
MySQL
System Date/Time
SELECT FROM_UNIXTIME(UNIX_TIMESTAMP(NOW()));
Current Date/Time
SELECT CURRENT_TIMESTAMP;
SELECT NOW();
Bibliography
MS-SQLhttps://docs.microsoft.com/en-us/sql/t-sql/functions/odbc-scalar-functions-transact-sql?view=sql-server-ver15https://docs.microsoft.com/en-us/sql/relational-databases/collations/write-international-transact-sql-statements?view=sql-server-ver15https://nocolumnname.blog/2020/11/20/uncommon-sql/https://nocolumnname.blog/2020/10/05/odc-date-time-extension-option-in-sql-server/https://stackoverflow.com/questions/33228765/how-do-i-specify-date-literal-when-writing-sql-query-from-sql-server-that-is-lin
MySQLhttps://www.w3schools.com/sql/func_mysql_curdate.asphttps://www.epochconverter.com/programming/mysqlhttps://www.w3schools.com/mysql/func_mysql_now.asp