fix the date of the previous day at 00:00 hours

2

I need to get MySQL the date of the previous day at 00:00 hours.

For example if today is 21/11/2017 11:57:00 , the resulting date should be% 20/11/2017 0:00:00.000 .

In sybase I take it out this way

SELECT dateadd (dd, 0,convert (varchar (10),getdate(), 101))

However, in MySQL I do not get it.

    
asked by ekom77 21.11.2017 в 12:18
source

2 answers

1

You should calculate the current date and time minus one day and less the current time.

Something like

SELECT (CURRENT_TIMESTAMP - INTERVAL 1 DAY) - INTERVAL CURRENT_TIME HOUR_SECOND
    
answered by 21.11.2017 / 12:33
source
1

You can use CURRENT_DATE (or CURDATE()) , which returns today's date at midnight, and remove a day using INTERVAL :

select current_date - interval 1 day

Demo

    
answered by 21.11.2017 в 12:35