codeigniter - make a difference in the two dates with database

513 Views Asked by At

Help me .. !! I 'm in the final project , build a web with Framwork CodeIgniter . 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

2

There are 2 best solutions below

1
David Coder On BEST ANSWER

irwan you have to run cron job for check the date daily. By cron job run this code :

$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 :)

2
Niranjan N Raju On
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)