php - Filtering record from last month and current year -


i need query, 1 works fine, thing returns me ingresos. need retrieve records of last month , current year.

i have tried interval 1 month returns me previous month based on today's day. need records of last month without counting first last date.

this 1 when e page loaded first:

select * ingresos fechareporteing < date_sub(curdate(),interval dayofmonth(curdate()) day) 

and 1 when user selects specific month:

select * ingresos fechareporteing < date(concat(year(curdate()),"-",'.$_post['mes'].',"-","0")) 

this works me. used php calculate date based on month selected user.

<?php //get users month. $month = isset($_get['mes'])? $_get['mes'] : "04"; //starting date string `current year`-`user month`-`first day` $startdatetext = date('y') . "-" . $month . "-01";  //add 1 month starting date. $startdate = date_create($startdatetext); $enddate = date_add($startdate, date_interval_create_from_date_string('1 month'));  //string representation of date $enddatetext = date_format($enddate, 'y-m-d');  echo "<br><br>search records on or after $startdatetext before $enddatetext.<br><br>";  $query = "select * ingresos     fechareporting >= '$startdatetext' && fechareporting < '$enddatetext' ";  $alldata = mysqli_query($db_conx, $query) or printf(mysqli_error($db_conx)); $totaldatarows = mysqli_num_rows($alldata); .... .... ?> 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -