Now we'll learn how to get the current date and time.
PostgreSQL actually has several functions you can use to get the current date and time. Each function returns different details.
Let's start with the simplest function:
NOW(). It returns the current date and time with time zone. Here's how you use it:
It's very simple, right?
CURRENT_TIMESTAMP function works exactly like
NOW(). You don't need parentheses with this function, just the name will do:
This returns a date and time with fractional seconds and includes the time zone information.
Why do we have two functions that do the same thing?
CURRENT_TIMESTAMP follows the ANSI SQL standard;
NOW() is the PostgreSQL version.