In PostgreSQL, the make_timestamp()
function allows you to create a timestamp from its year, month, day, hour, minute and seconds fields.
Tag: functions
How statement_timestamp() Works in PostgreSQL
In PostgreSQL, the statement_timestamp()
function returns the current date and time (including the time zone offset), at the start of the current statement.
The function doesn’t accept any parameters, so you can’t specify its precision.
Also, statement_timestamp()
is a non-SQL-standard function.
How transaction_timestamp() Works in PostgreSQL
In PostgreSQL, the transaction_timestamp()
function returns the current date and time (including the time zone offset), at the start of the current transaction.
It’s the equivalent of the traditional Postgres function now()
.
It’s also similar to the current_timestamp
function (when called without an argument), except that it’s named to clearly reflect what it does.
The transaction_timestamp()
function doesn’t accept any parameters, so you can’t specify its precision, whereas current_timestamp
can be called with or without a precision parameter.
Also, transaction_timestamp()
is a non-SQL-standard function.
How Now() Works in PostgreSQL
In PostgreSQL, the now()
function returns the current date and time (including the time zone offset), at the start of the current transaction.
It’s the equivalent of the transaction_timestamp()
function.
It’s also similar to the current_timestamp
function (when called without an argument).
The now()
function doesn’t accept any parameters, so you can’t specify its precision, whereas current_timestamp
can be called with or without a precision parameter.
Also, now()
is non-SQL-standard (as is the transaction_timestamp()
function).
How timeofday() Works in PostgreSQL
In PostgreSQL, timeofday()
is a non-SQL-standard time function that returns the current date and time, with the time zone abbreviation.
It’s similar to the clock_timestamp()
function, except that it returns its result as a formatted text
string rather than a timestamp with time zone
value.
The result of both functions changes throughout the execution of a statement. Therefore, you could get a different result in different parts of the statement if you call the functions multiple times within a single statement.
Continue readingHow LocalTime() Works in PostgreSQL
In PostgreSQL, the localtime
function returns the local time of the day, without the time zone offset.
If you need the time zone offset, use current_time()
instead.
How current_time Works in PostgreSQL
In PostgreSQL, the current_time
function returns the current time, including the time zone offset.
The time returned is based on the start time of the current transaction.
Continue readingHow current_date Works in PostgreSQL
In PostgreSQL, the current_date
function returns the current date.
How date_trunc() Works in PostgreSQL
In PostgreSQL, the date_trunc()
function truncates a date/time value to a specified precision.
It can also truncate the value to a specified precision in a specified time zone.
You could think of it as a date version of the trunc()
function (which truncates numbers).
How the to_number() Function Works in PostgreSQL
In PostgreSQL, you can use the to_number()
function to convert a string to a numeric value.
More specifically, it converts the string representation of a number to a numeric value.
For example, if you have $1,234.50
as a string, you can use to_number()
to convert that to an actual number that uses the numeric data type.