i.e
Suppose the current date is 18/10/2016 then i want to fetch all record from 18/10/206 to 30/11/2016
This is the scenario, please help me to get effective way to fetch this from in a single query mysql.
i.e
Suppose the current date is 18/10/2016 then i want to fetch all record from 18/10/206 to 30/11/2016
This is the scenario, please help me to get effective way to fetch this from in a single query mysql.
You can use BETWEEN
to compare dates.
Take help of LAST_DAY(date)
function.
SELECT
*
FROM your_table
WHERE your_date BETWEEN CURDATE() AND LAST_DAY(CURDATE() + INTERVAL 1 MONTH)
Note:
LAST_DAY() function
MySQL LAST_DAY()
returns the last day of the corresponding month for a date or datetime value. If the date or datetime value is invalid, the function returns NULL
.
$time = strtotime(date('Y-m-d'));
$final = date("Y-m-d", strtotime("+1 month", $time));
$nextMonth= date('t/m/Y',strtotime($final));
$now=date('d/m/Y');
$sql="select * from table where date>='".$now.' and date<=$nextMonth";
$res=mysql_query($sql);