Function is_date
The function checks strings for being a date.
You might pass a second parameter to use a format string. Without the format, the default format of PostgreSQL is used.
There has been a behaviour change in PostgreSQL 10. A conversion is now handled strict, in previous versions the conversion tried to calculate dates.
Examples
/**
* Parameter is in PostgreSQL default format
*/
SELECT is_date('2018-01-01') AS res;
Result:
| res |
|---|
| t |
SELECT is_date('2018-02-31') AS res;
Result:
| res |
|---|
| f |
/**
* Parameter is in PostgreSQL German format
*/
SELECT is_date('01.01.2018', 'DD.MM.YYYY') AS res;
Result:
| res |
|---|
| t |
SELECT is_date('31.02.2018', 'DD.MM.YYYY') AS res;
Result:
| res |
|---|
| f |