gpt4 book ai didi

php - 使用 CodeIgniter 以日期格式计算数据库中每月、每年的日期

转载 作者:行者123 更新时间:2023-11-29 11:43:33 25 4
gpt4 key购买 nike

如何根据数据库中的日期根据日期格式计算1bulan/1年的数据量?我使用的是codeigniter

示例

date 2016-02-10

2016-05-19

2016-07-20

2016-02-30

2016-05-20

2016-05-21

结果计数

data on Mounth Feb = 2

data on Mounth May = 3

data on Mounth Jul = 1

这是我的脚本

<?php 
$sql = "SELECT * FROM tbcounter ";
$get_monthly = " WHERE date LIKE '".date("Y-m")."%'";
$monthly = mysql_num_rows(mysql_query($sql . $get_monthly));
echo $monthly;
?>

最佳答案

您可以使用 DATE_FORMAT(date_column,'desired_output') ,如下例所示:-您可以在 http://php.net/manual/en/function.date.php 上阅读有关日期函数的信息

$date_variable = date("Y-m",strtotime('last month')); //prints 2016-01 
echo $this->db->get_where("tbcounter",array("DATE_FORMAT(`date`,'%Y-%m')"=> $date_variable ))->num_rows();

这是演示代码:)

关于php - 使用 CodeIgniter 以日期格式计算数据库中每月、每年的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35354341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com