Remove 1 day from a specific date

Asked

Viewed 155 times

0

Good morning, everyone! I would like a help regarding the database, where I pick a date and after I pick up this date I need to remove 1 day from it, thus pulling the result from 1 day prior to the informed date. How could I do that?

AND ped_data BETWEEN '2016-01-01 00:00:00' AND '2020-03-31 23:59:59' - EXAMPLE

I need to withdraw the day on the second date informed, thanks in advance.

2 answers

3

Depending on which server you are using has a function to add/subtract dates.

MYSQL

DATE_ADD("2017-06-15", INTERVAL -1 DAY)

SQL Server

DATEADD (day, -1, "2017-06-15")

Postgresql

DATE '2017-06-15' - INTERVAL '1 day'
  • Hello guys, thank you so much for the help, it worked super well using the "INTERVAL", now I know how to apply it when I have to solve problems like these, I thank you very much for the help and patience, all good for you always

0


Could use the function DATEADD if you are using SQL.

AND ped_data BETWEEN '2016-01-01 00:00:00' AND DATEADD(dd, -1, '2020-03-31 23:59:59')

Where dd means Day, and -1 means you will subtract 1.

Or if you are using Mysql, you can use the function ADDDATE.

AND ped_data BETWEEN '2016-01-01 00:00:00' AND ADDDATE('2020-03-31 23:59:59', INTERVAL -1 DAY)

Where -1 means that you will subtract 1, and DAY means that the day will be changed.

I hope I’ve helped.

  • Hello Thrnk, as I am using in Postgresql I used the "INTERVAL - 1 DAY" and it worked super well, thank you very much for your help and patience, that you grow quite professionally, strong hugs.

Browser other questions tagged

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