简体   繁体   中英

Get last month and current month record of user in codeigniter active record

We want to get the records of last month of user point. We have User Created date Ex. 25-08-2015 . Second table is user points.

But Main Thing is : -

if current date is 23-11-2015

we want record between in point table: -

last month: 25-09-2015 to 25-10-2015

Current Month : 25-10-2015 to 25-11-2015

if current date is 28-11-2015

we want redcord between in point table:-

last month: 25-10-2015 to 25-11-2015

Current Month : 25-11-2015 to 25-12-2015

Note: Means User Created date is starting user month and end of user month

You can do following:

function get_day_for_date($date)
{
     $day = date('d', strtotime($date));
     return $day;
}

$user_reg = "25-08-2015";

$current_month_start = get_day_for_date($user_reg) ."-". date("m-Y",    strtotime("-1 months"));
$current_month_end = get_day_for_date($user_reg) ."-". date("m-Y");

$last_month_start = get_day_for_date($user_reg) ."-". date("m-Y",  strtotime("-2 months"));
$last_month_end = get_day_for_date($user_reg) ."-". date("m-Y", strtotime("-1 month"));

//echo $current_month_start . ", ". $current_month_end;
//echo "<br>";
//echo $last_month_start . ", ". $last_month_end;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM