php - 获取codeigniter事件记录中用户的上个月和当月记录

标签 php mysql codeigniter date

我们想要获取上个月的用户积分记录。 我们有用户创建日期例如。 2015 年 8 月 25 日。 第二个表是用户积分。

But Main Thing is : -

if current date is 23-11-2015

我们想要点表中的记录:-

上个月:2015年9月25日至2015年10月25日

当前月份:2015年10月25日至2015年11月25日

if current date is 28-11-2015

我们想要点表之间的红线:-

上个月:2015年10月25日至2015年11月25日

当前月份:2015年11月25日至2015年12月25日

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

最佳答案

您可以执行以下操作:

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;

关于php - 获取codeigniter事件记录中用户的上个月和当月记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33866081/

相关文章:

php - 我怎样才能编写这段代码来实现相同的结果,但只使用一个 foreach 语句?

php - 显示 MySQL 中包含相同值的所有行

php - 加载不同的数据库取决于用户的登录?

php - 如何检索 PDO 结果==false?

php - Codeigniter 的数据库错误

Javascript 在 html 中复制一个 div 并从表单提交中复制的 div 中获取值

javascript - 无法使用 PHP 显示警报消息

php - 如何格式化 GROUP BY 查询的输出?

mysql - 如何使用联接从表中搜索?

javascript - Codeigniter:在 Controller 中定义 JSON 变量