I am new to PostgresQL and PHP and am working with a PostgresQL Timestamp object and am trying to find the difference between now and that timestamp to display in terms of years, months, and days. Is there to do this?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can just subtract two timestamps, the result is an
interval.To get “now” you can use
now()orcurrent_timestamp(among others).This will display something like this, though:
To get a justified representation, use
age()orjustify_interval()Displays the same value in a format like you seem to be after:
If you want a particular output format use
to_char()