INSERT IN SQL DATEADD Yesterday

I want to use PHP and MySQL for INSERT on the day Yesterday. Therefore my idea:

INTO chartValues SET timestamp='1353369600', `datetime`=DATEADD(d,-1,GETDATE()) 

But its not working:

1064 - You have an error in the SQL syntax; check the manual that matches your version of MySQL server for the correct syntax to use near 'INTO chartValues ​​SET timestamp =' 1353369600 ', datetime = DATEADD (d, -1, GETDATE ())' on line 1

Thank you in advance

+4
source share
4 answers

DATEADD and GETDATE() are the T-SQL functions used in SQL Server.

Do you want to use DATE_ADD() or DATE_SUB() with NOW()

 INSERT INTO chartValues SET timestamp='1353369600', `datetime`= DATE_SUB(NOW(), INTERVAL 1 DAY) 

Link

DATE_SUB(date, INTERVAL expr unit)

+4
source

I believe that you should use NOW() in MySql instead of getdate() . See Mysql Date and Time Functions .

0
source

Date_add () not dateadd () now () not getdate ()

The link below is a good mysql programming link. I recommend it.

so datetime = date_add (d, -1, now ())

http://www.w3schools.com/sql/func_date_add.asp

0
source

You can use something like this in php:

 date("F j, Y", time() - 60 * 60 * 24); 

depending on the type of data in your database, you can change "F j, Y" in the format you need.

In mysql something like this:

 CAST(NOW() - INTERVAL 1 DAY AS DATE). 
0
source

Source: https://habr.com/ru/post/1447538/


All Articles