Removing "BC" from Timestamp dates in Postgresql

Asked

Viewed 158 times

1

Hello, I’m trying to remove "BC" from sql dates but I’m not getting.
I’ll tell you what:

 SELECT CAST("regiaulaavul_dataInicio" AS date) FROM "RegistroAulaAvulsa"

And eventually return me the date with a BC (Before Christ) in front. I would like to remove it to compare with the current date, which does not bring the BC. Making comparisons between both returns incorrect result.

inserir a descrição da imagem aqui

Thank you,
Lucas Kunze.

  • 1

    Try this: SELECT DATE_FORMAT(regiaulaavul_dataInicio, '%M %d, %Y') FROM RegistroAulaAvulsa

  • Thanks for the help, I searched something compatible with DATE_FORMAT for postgres and found to_char, so I converted it to date and it worked.

  • Glad I helped, if possible post your solution to help those next who have this doubt

1 answer

1

With the help of comments and stackoverflow it was possible to find the following solution:

to_char("regiaulaavul_dataInicio"::date, 'YYYY-MM-DD')::date

First a conversion was made to the string format and then to date, thus removing the "BC" and allowing comparison with other dates.

  1. Comment from R.Santos
  2. https://stackoverflow.com/questions/12052705/date-format-in-postgresql

Browser other questions tagged

You are not signed in. Login or sign up in order to post.