I am using trunc
function in postgresql like trunc(date)
, but error is there "Function trunc(date) does not exist in postgresql". Please tell me the alternative function of trunc
in postgresql
I think you are looking for the date_trunc()
function, which is used to truncate timestamps. The trunc()
function is used for truncating numbers, not dates.
If you had a date and you wanted to truncate it to the hour, you could use:
date_trunc('hour', date)
If you wanted to truncate to the day, you could use this:
date_trunc('day', date)
Documentation
if you only want cut to hour you can cast timestamp variable to date example
timestamp_variable::date
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