Tuesday, August 13, 2013

how to automatically get the first date of the current month in mysql

there are several ways of doing it. here is how i do it. it just feels simpler this way :)


$mth = date('m');                               // gets the current month
$yr = date('Y');                                   // gets the current year

For example, if i want to run a query to get results between the first day of the current month and today, i would write it like this:-

"SELECT * FROM table WHERE date BETWEEN '$yr-$mth-01' AND CURDATE( )"

No comments:

Post a Comment