Functions for retrieving current date/time

Funzioni per manipolare i dati in PostgreSQL

Brian Piccolo

Sr. Director, Digital Strategy

Retrieving the current timestamp

SELECT NOW();
+-------------------------------+
| now()                         |
|-------------------------------|
| 2019-04-19 02:51:18.448641+00 |
+-------------------------------+
Funzioni per manipolare i dati in PostgreSQL

Retrieving the current timestamp

SELECT NOW()::timestamp;
+----------------------------+
| now()                      |
|----------------------------|
| 2019-04-19 02:51:18.448641 |
+----------------------------+
Funzioni per manipolare i dati in PostgreSQL

Retrieving the current timestamp

PostgreSQL specific casting

SELECT NOW()::timestamp;

CAST() function

SELECT CAST(NOW() as timestamp);
Funzioni per manipolare i dati in PostgreSQL

Retrieving the current timestamp

SELECT CURRENT_TIMESTAMP;
+-------------------------------+
| current_timestamp             |
|-------------------------------|
| 2019-04-19 02:51:18.448641+00 |
+-------------------------------+
Funzioni per manipolare i dati in PostgreSQL

Retrieving the current timestamp

SELECT CURRENT_TIMESTAMP(2);
+-------------------------------+
| current_timestamp             |
|-------------------------------|
| 2019-04-19 02:51:18.44+00     |
+-------------------------------+
Funzioni per manipolare i dati in PostgreSQL

Current date and time

SELECT CURRENT_DATE;
+--------------+
| current_date |
|--------------|
| 2019-04-19   |
+--------------+
Funzioni per manipolare i dati in PostgreSQL

Current date and time

SELECT CURRENT_TIME;
+------------------------+
| current_time           |
|------------------------|
| 04:06:30.929845+00:00  |
+------------------------+
Funzioni per manipolare i dati in PostgreSQL

Let's practice!

Funzioni per manipolare i dati in PostgreSQL

Preparing Video For Download...