I want to compute the difference of year between today's date and date of variable called "creation date" which is a timestamp without time zone. This is the code I used. However, it returned this error "syntax error at or near ")"". I have no idea why.
select DATEDIFF(year, ('2020/01/01', to_date (created_at, 'YYYY/MM/DD') ))
Try this:
SELECT DATEDIFF(curdate(), created_at);
DATEDIFF
function will return the number of days between two dates. curdate()
will give you the current date.
If that does not work, try this:
DATEDIFF(year, CURRENT_TIMESTAMP, created_at)
Or this:
SELECT DATE_PART('year', CURRENT_DATE) - DATE_PART('year', created_at::date);
The above options are different options depending on the database. I do not know what does https://mode.com/online-sql-editor/ support.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.