I have a table containing data about events and festivals with following columns recording their start and end dates.
date format is in YYYY-MM-DD
. I need to fetch event details with the following condition.
currentDate+next30days
.I am clear about end date concept. but not sure how I can fetch data whose start dates are in a current month.
For this, I need to compare current year and current month against the Start_Date
column in my database.
Can anyone help me to point out as how I can do that?
As below screenshot shown, supposing you need to compare two date lists and match the dates by month and year only, you can apply the below formula to achieve it. 1. Select a blank cell, enter formula =MONTH(A2)&YEAR(A2)=MONTH(B2)&YEAR(B2) into the Formula Bar, and then press the Enter key.
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 .
In SQL, the date value has DATE datatype which accepts date in 'yyyy-mm-dd' format. To compare two dates, we will declare two dates and compare them using the IF-ELSE statement. We can declare variables easily by using the keyword DECLARE before the variable name.
select * from your_table
where year(Start_Date) = year(curdate())
and month(Start_Date) = month(curdate())
and end_date <= curdate() + interval 30 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