Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding 12 hours to mysql current timestamp

Tags:

date

mysql

I am trying to filter my query data to only return items where "Meeting Start" is greater than CURRENT_TIMESTAMP but not later than 12 hours from the CURRENT_TIMESTAMP.

Can I add 12 hours to the CURRENT_TIMESTAMP inline below in my query?

Current Working Query:

$query ="SELECT * FROM Reservations WHERE [Room_ID] = '$field' AND [Meeting Start] > CURRENT_TIMESTAMP ORDER BY [Meeting Start] asc ";

Updated Try:

$query ="SELECT * FROM Reservations WHERE [Room_ID] = '$field' AND [Meeting Start] > CURRENT_TIMESTAMP AND [Meeting Start] < (CURRENT_TIMESTAMP + 12) ORDER BY [Meeting Start] asc ";
like image 688
Denoteone Avatar asked Nov 09 '11 19:11

Denoteone


People also ask

What is Date_add 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. Syntax: DATE_ADD(date, INTERVAL value addunit) Parameter: This function accepts two parameters which are illustrated below: date – Specified date to be modified.

What is Date_sub in MySQL?

The DATE_SUB() function subtracts a time/date interval from a date and then returns the date.


1 Answers

NOW() + INTERVAL 12 HOUR should do the trick. +12 is ambiguous. 12 seconds? minutes? days? years?

like image 164
Marc B Avatar answered Nov 20 '22 20:11

Marc B