I'm trying to make the following work in PostgreSQL:
SELECT * FROM purchases WHERE CONVERT(expiration_date) < '2013-03-21 13:14:00'
Where CONVERT
is some method that would convert Date
to DateTime
. Any idea how to do this?
PostgreSQL Convert DateTime to Date Using EXTRACT() Function EXTRACT() function takes in two arguments, field and source. The field argument specifies the date part, i.e. month, decade, hour, to extract from the DateTime value. The source argument is a value of type TIMESTAMP or INTERVAL.
You can specify double colons (::) to cast a DATETIME value to a DATE value. You can combine TO_CHAR() and the Now() function to convert the current timestamp into the specified format.
How do I change the date format from YYYY-MM-DD in PostgreSQL? 1) Get the current date To get the current date and time, you use the built-in NOW() function. However, to get the date part only (without the time part), you use the double colons (::) to cast a DATETIME value to a DATE value.
PostgreSQL supports the full set of SQL date and time types, shown in Table 8.9. The operations available on these data types are described in Section 9.9.
There is no DateTime
type in PostgreSQL, there's timestamp
.
To convert simply do expiration_date::timestamp
but I think it should work without conversion. WHERE expiration_date < '2013-03-21 13:14:00'
should be valid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With