offers.date = CURDATE()
I what I currently have.
It grabs offers for today, but I also would like to grab the orders for yesterday.
How can I do this, without specifying the yesterday's date?
The CURDATE() function returns the current date. Note: The date is returned as "YYYY-MM-DD" (string) or as YYYYMMDD (numeric). Note: This function equals the CURRENT_DATE() function.
You can use DATE() from MySQL to select records with a particular date. The syntax is as follows. SELECT *from yourTableName WHERE DATE(yourDateColumnName)='anyDate'; To understand the above syntax, let us first create a table.
To get yesterday's date, you need to subtract one day from today's date. Use CURDATE() to get today's date. In MySQL, you can subtract any date interval using the DATE_SUB() function. Here, since you need to subtract one day, you use DATE_SUB(CURDATE(), INTERVAL 1 DAY) to get yesterday's date.
To count the difference between dates in MySQL, use the DATEDIFF(enddate, startdate) function. The difference between startdate and enddate is expressed in days. In this case, the enddate is arrival and the startdate is departure .
To use CURDATE minus or plus a interval (e.g. yesterday) you can use the DATE_ADD function
SELECT DATE_ADD(CURDATE(), INTERVAL -1 DAY);
So, in your case you use it like this:
WHERE offers.date = CURDATE() OR offers.date = DATE_ADD(CURDATE(), INTERVAL -1 DAY)
Optionally you can also use the DATE_SUB() function and instead of a negative interval use the same interval but positive.
Thus, DATE_ADD(CURDATE(), INTERVAL -1 DAY)
would become DATE_SUB(CURDATE(), INTERVAL 1 DAY)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With