简体   繁体   English

codeigniter-使用数据库在两个日期中有所作为

[英]codeigniter - make a difference in the two dates with database

Help me .. !! 帮我 .. !! I 'm in the final project , build a web with Framwork CodeIgniter . 我正在最后一个项目中,使用Framwork CodeIgniter构建一个Web。 but I difficulty to make a difference in the control script , the examples I list dated 07.02.2015 and should regristasi before 3 days but I forgot to register so it appears the warning .. how to make 但是我很难在控制脚本中有所作为,我列出的示例日期为07.02.2015,应该在3天前进行注册,但是我忘记注册了,因此出现了警告..

irwan you have to run cron job for check the date daily. irwan,您必须每天运行cron作业以检查日期。 By cron job run this code : 通过cron job运行以下代码:

$current_date=date('Y-m-d');
$date = strtotime($date);
$date = strtotime("+3 day", $date);
$adate=date=date('Y-m-d', $date); // this is after three days's date.

then run the query: 然后运行查询:

$this->db->where('date',$adate);
$q=$this->db->get('table');

then do something(whatever you want like send mail or anything) if you get data from above query. 如果您从上述查询中获取了数据,请执行某项操作(无论您想要发送邮件还是执行任何操作)。 Hope you got the point :) 希望你明白了:)

CREATE TABLE date (date1 timestamp, date2 timestamp);

INSERT INTO date VALUES ('2010-03-11 12:00:00', '2010-03-30 05:00:00');
INSERT INTO date VALUES ('2010-03-11 12:00:00', '2010-03-30 13:00:00');
INSERT INTO date VALUES ('2010-03-11 00:00:00', '2010-03-30 13:00:00');
INSERT INTO date VALUES ('2010-03-10 12:00:00', '2010-03-30 13:00:00');
INSERT INTO date VALUES ('2010-03-10 12:00:00', '2010-04-01 13:00:00');

SELECT date2 as d2,date1 as d1, DATEDIFF(d2, d1) AS diff FROM date;

+---------------------+---------------------+------+
| d2                  | d1                  | diff |
+---------------------+---------------------+------+
| 2010-03-30 05:00:00 | 2010-03-11 12:00:00 |   19 |
| 2010-03-30 13:00:00 | 2010-03-11 12:00:00 |   19 |
| 2010-03-30 13:00:00 | 2010-03-11 00:00:00 |   19 |
| 2010-03-30 13:00:00 | 2010-03-10 12:00:00 |   20 |
| 2010-04-01 13:00:00 | 2010-03-10 12:00:00 |   22 |
+---------------------+---------------------+------+
5 rows in set (0.00 sec)

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

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