Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use DATEADD in MySQL?

Tags:

sql

mysql

I have a problem and I can't figure out the solution. With a previously asked question (SELECT rows with time 30 minutes or less?) I tried to make my COUNT(*) function work but I can't make it work. Anybody an idea?

SELECT COUNT(*) FROM g_ad_view WHERE ad_view_time >= DATEADD(mi, -30, GETDATE())

And this is the error I get back:

SQLSTATE[42000]: Syntax error or access violation: 1305 FUNCTION 18RVS15.DATEADD does not exist

like image 829
Bart Scheffer Avatar asked Aug 28 '14 12:08

Bart Scheffer


People also ask

Does Dateadd work in MySQL?

DATE_ADD() function in MySQL is used to add a specified time or date interval to a specified date and then return the date. Specified date to be modified. Here the value is the date or time interval to add. This value can be both positive and negative.

How can I add 15 days to current date in MySQL?

Use the DATE_ADD() function if you want to increase a given date in a MySQL database. In our example, we increased each start date by two days. This function takes two arguments.

How add days to now in MySQL?

INSERT INTO yourTableName VALUES(DATE_ADD(now(),interval n day)); In the above syntax, you can use curdate() instead of now(). The curdate() will store only date while now() will store both date and time.

What is Dateadd SQL?

The DATEADD() function adds a time/date interval to a date and then returns the date.


2 Answers

The MySQL syntax is:

WHERE ad_view_time >= now() - interval 30 minute
like image 58
Gordon Linoff Avatar answered Oct 07 '22 15:10

Gordon Linoff


DateAdd is missspelled: It must be DATE_ADD (with underscore). See the documentation

like image 26
Jens Avatar answered Oct 07 '22 13:10

Jens