Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select where date relative to now()

Tags:

sql

mysql

I am trying to find all results with an end date within 30 days of now. The query I am trying for is:

SELECT * FROM title WHERE sales_end-date < now() + 30 days

How would I do this properly?

like image 288
David542 Avatar asked Nov 15 '12 21:11

David542


People also ask

How to use select date in SQL Server?

In Microsoft SQL Server, SELECT DATE is used to get the data from the table related to the date, the default format of date is ‘YYYY-MM-DD’. WHERE condition1, condition2,..; Now we will execute queries on SELECT DATE on database student in detail step-by-step:

What is the date and time in now () syntax?

Note:The date and time is returned as "YYYY-MM-DD HH-MM-SS" (string) or as YYYYMMDDHHMMSS.uuuuuu (numeric). Syntax NOW() Technical Details Works in:

How do I view items with a date on or after?

To view items with a date on or after Feb 2, 2012, use the >= operator instead of the > operator. Returns items with a date between Feb 2, 2012 and Feb 4, 2012. Note: You can also use the Between operator to filter for a range of values, including the end points.

How do I find items with dates in access?

If today's date is Feb 2, 2012, you’ll see items for Feb 3, 2012. DatePart ("ww", [SalesDate]) = DatePart ("ww", Date ()) and Year ( [SalesDate]) = Year (Date ()) Returns items with dates during the current week. A week in Access starts on Sunday and ends on Saturday.


1 Answers

Use INTERVAL

SELECT * 
  FROM title 
 WHERE sales_end-date < DATE_ADD(CURRENT_TIMESTAMP, INTERVAL 30 day)
like image 195
John Conde Avatar answered Oct 02 '22 21:10

John Conde