0

I have a table which looks like this:

datestamp
2020-04-01
2020-04-02

I am trying to do two things:

  1. Convert datestamp to date format, because right now it's ABC
  2. Get difference between datestamp and the end of this year ( 2020-12-31 )

So that I would get a result like this:

datestamp      diff
2020-04-01     275
2020-04-02     274

What I've tried:

DATEDIFF(day, datestamp, '2020-12-31 00:00:00.0000000')

I get:

DATEDIFF(day, datestamp, '2020-12-31 00:00:00.0000000')

Where is my mistake?

1
  • 1
    Where in the manual did you find datediff() Commented Apr 2, 2020 at 12:15

1 Answer 1

2

Simply subtract the values:

select datestamp, date '2020-12-31' - datestamp as diff
from the_table;

This assumes that datestamp is a date column.

Sign up to request clarification or add additional context in comments.

2 Comments

At the moment datestamp is a text column, what would be the easiest way to convert it to date?
@JonasPalačionis: as documented in the manual cast(datestamp as date) or datestamp::date - but that only works if all values can be cast without an error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.