From 6442155bb6b9da86188989508ae17a7ba0ae558e Mon Sep 17 00:00:00 2001 From: Adeilton Santana Aguiar Filho <93356734+adeiltonsantanaa@users.noreply.github.com> Date: Wed, 25 Jan 2023 15:39:03 -0300 Subject: [PATCH] Creating a reference to some date functions adding some very used and important date functions --- source/_posts/postgres.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/source/_posts/postgres.md b/source/_posts/postgres.md index b5984a5..487771c 100644 --- a/source/_posts/postgres.md +++ b/source/_posts/postgres.md @@ -332,6 +332,26 @@ DROP SCHEMA IF EXISTS CASCADE; ``` +### Dates + +Show [current date](https://www.postgresql.org/docs/15/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT) YYYY-MM-DD +```sql {.wrap} +SELECT current_date; +``` +Calculate [age](https://www.postgresql.org/docs/15/functions-datetime.html#:~:text=age%20(%20timestamp%2C%20timestamp%20)%20%E2%86%92%20interval) between two dates +```sql {.wrap} +SELECT age(timestamp, timestamp); +``` +Show [current time](https://www.postgresql.org/docs/15/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT) with time zone +```sql {.wrap} +SELECT current_time; +``` +[Make](https://www.postgresql.org/docs/15/functions-datetime.html#:~:text=make_date%20(%20year%20int%2C%20month%20int%2C%20day%20int%20)%20%E2%86%92%20date) dates using integers +```sql {.wrap} +SELECT make_date(2021,03,25); +``` + + PostgreSQL Commands -----------