简体   繁体   English

在codeigniter活动记录中获取用户的上个月和当月记录

[英]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. 我们有用户创建的日期Ex。 25-08-2015 . 2015年5月25日 Second table is user points. 第二个表是用户点数。

But Main Thing is : - 但是主要的事情是:-

if current date is 23-11-2015 如果当前日期为2015年11月23

we want record between in point table: - 我们要在点表之间记录:-

last month: 25-09-2015 to 25-10-2015 上个月: 2015-09-25至2015-10-25

Current Month : 25-10-2015 to 25-11-2015 当前月份: 2015年1025日至2015年1125日

if current date is 28-11-2015 如果当前的日期是28-11-2015

we want redcord between in point table:- 我们要在点表之间使用redcord:-

last month: 25-10-2015 to 25-11-2015 上个月: 2015年1025日至2015年1125日

Current Month : 25-11-2015 to 25-12-2015 当前月份: 2015年1125日至2015年1225日

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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