php - HOw to SELECT * (all) which date start from the last day of last month to the first day of next month -


use php , mysql , want use select statement date_post(datetime variable) start @ last date of last month , date first day of next month, me please.

thank in advance.

my database: 'id', 'content', 'image', 'date_post',  

etc. , try use

$today = getdate(); $thisyear=$today['year']; $thismon=$today['mon']; $date_start=$thisyear.'-'.$thismon.'-01'; $date_end=$thisyear.'-'.($thismon+1).'-01'; $sql="select *, date_format(date_post, '%d-%m-%y') datepost       my_table       date_post between date('$date_start')          , date('$date_end')       order date_post desc";  

it makes 1 query in mysql, without php:

select * `table_name` date(`date_post`) >= date_format(curdate() - interval 1 month, concat('%y-%m-', day(last_day(curdate() - interval 1 month)))) , date(`date_post`) <= date_format(curdate() + interval 1 month, '%y-%m-01'); 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -