sql - Difference in years between two dates -


i have table in postgresql has column datatype timestamp named birthdate, possible write sql statement return difference in years birthdate stored in table , current date? how done? server postgresql

this have tried giving me syntax error @ second select

select datediff(yy, now(), select birthdate match match_id = '550856d8560a64ed180416d1556f5435f4bb054c68930040') 

there number of things wrong here.

select datediff        ^^^^        postgresql doesn't have datediff function.  regress-> \df datediff                        list of functions  schema | name | result data type | argument data types | type  --------+------+------------------+---------------------+------ (0 rows) 

i think want - operator, extract function, justify_interval , to_char function. also, write current_timestamp instead of now(), it's standard spelling.

also this:

(yy, now(), select birthdate ...)             ^^^ 

is syntax error because didn't wrap subquery in (parentheses), should be:

(yy, now(), (select birthdate  ...)) 

but in case no subquery necessary because can flatten outer query, gives when subquery fixed nothing else is:

select datediff(yy, now(), birthdate) match match_id = '550856d8560a64ed180416d1556f5435f4bb054c68930040'; 

and date subtraction:

regress=> select extract(year justify_interval(current_timestamp - date '2008-02-01'));  date_part  -----------          7 (1 row) 

giving like:

select extract(year justify_interval(current_timestamp - birthdate)) match match_id = '550856d8560a64ed180416d1556f5435f4bb054c68930040'; 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -