viernes, 19 de febrero de 2016

checking diffrence of hours and days

Hour differences
mysql> select * ,TIMEDIFF(now(),time),now()  from calls order by time desc;
+----+-------------+-------------+---------------------+------------+------------+----------------------+---------------------+
| id | phone       | did         | time                | rerserved2 | rerserved3 | TIMEDIFF(now(),time) | now()               |
+----+-------------+-------------+---------------------+------------+------------+----------------------+---------------------+
|  7 | 18099221258 | 13065201258 | 2016-02-19 20:09:46 |       NULL |       NULL | 00:38:37             | 2016-02-19 20:48:23 |
|  6 | 15122361010 | 14587143030 | 2016-02-19 20:09:27 |       NULL |       NULL | 00:38:56             | 2016-02-19 20:48:23 |
|  5 | 9100        | 101         | 2016-02-17 00:27:25 |       NULL |       NULL | 68:20:58             | 2016-02-19 20:48:23 |
|  4 | 9100        | 101         | 2016-02-17 00:27:22 |       NULL |       NULL | 68:21:01             | 2016-02-19 20:48:23 |
|  3 | 13052361010 | 100         | 2016-01-22 21:58:49 |       NULL |       NULL | 670:49:34            | 2016-02-19 20:48:23 |
|  2 | 13052361010 | 18007143030 | 2016-01-22 21:57:34 |       NULL |       NULL | 670:50:49            | 2016-02-19 20:48:23 |
|  1 | 13052361010 | 18007143030 | 2016-01-22 21:56:21 |       NULL |       NULL | 670:52:02            | 2016-02-19 20:48:23 |
+----+-------------+-------------+---------------------+------------+------------+----------------------+---------------------+
7 rows in set (0.00 sec)


Day difference

mysql> select * ,datediff(now(),time),now()  from calls order by time desc;
+----+-------------+-------------+---------------------+------------+------------+----------------------+---------------------+
| id | phone       | did         | time                | rerserved2 | rerserved3 | datediff(now(),time) | now()               |
+----+-------------+-------------+---------------------+------------+------------+----------------------+---------------------+
|  7 | 18099221258 | 13065201258 | 2016-02-19 20:09:46 |       NULL |       NULL |                    0 | 2016-02-19 20:50:18 |
|  6 | 15122361010 | 14587143030 | 2016-02-19 20:09:27 |       NULL |       NULL |                    0 | 2016-02-19 20:50:18 |
|  5 | 9100        | 101         | 2016-02-17 00:27:25 |       NULL |       NULL |                    2 | 2016-02-19 20:50:18 |
|  4 | 9100        | 101         | 2016-02-17 00:27:22 |       NULL |       NULL |                    2 | 2016-02-19 20:50:18 |
|  3 | 13052361010 | 100         | 2016-01-22 21:58:49 |       NULL |       NULL |                   28 | 2016-02-19 20:50:18 |
|  2 | 13052361010 | 18007143030 | 2016-01-22 21:57:34 |       NULL |       NULL |                   28 | 2016-02-19 20:50:18 |
|  1 | 13052361010 | 18007143030 | 2016-01-22 21:56:21 |       NULL |       NULL |                   28 | 2016-02-19 20:50:18 |
+----+-------------+-------------+---------------------+------------+------------+----------------------+---------------------+

numbers of hours

mysql> select * ,hour(TIMEDIFF(now(),time)),now()  from calls order by time desc;
+----+-------------+-------------+---------------------+------------+------------+----------------------------+---------------------+
| id | phone       | did         | time                | rerserved2 | rerserved3 | hour(TIMEDIFF(now(),time)) | now()               |
+----+-------------+-------------+---------------------+------------+------------+----------------------------+---------------------+
|  7 | 18099221258 | 13065201258 | 2016-02-19 20:09:46 |       NULL |       NULL |                          1 | 2016-02-19 21:40:20 |
|  6 | 15122361010 | 14587143030 | 2016-02-19 20:09:27 |       NULL |       NULL |                          1 | 2016-02-19 21:40:20 |
|  5 | 9100        | 101         | 2016-02-17 00:27:25 |       NULL |       NULL |                         69 | 2016-02-19 21:40:20 |
|  4 | 9100        | 101         | 2016-02-17 00:27:22 |       NULL |       NULL |                         69 | 2016-02-19 21:40:20 |
|  3 | 13052361010 | 100         | 2016-01-22 21:58:49 |       NULL |       NULL |                        671 | 2016-02-19 21:40:20 |
|  2 | 13052361010 | 18007143030 | 2016-01-22 21:57:34 |       NULL |       NULL |                        671 | 2016-02-19 21:40:20 |
|  1 | 13052361010 | 18007143030 | 2016-01-22 21:56:21 |       NULL |       NULL |                        671 | 2016-02-19 21:40:20 |
+----+-------------+-------------+---------------------+------------+------------+----------------------------+---------------------+
7 rows in set (0.00 sec)


selecting fields    with insertion date no longer than 1 hour

mysql> select * ,hour(TIMEDIFF(now(),time)),now()  from calls where hour(TIMEDIFF(now(),time))>=0 and hour(TIMEDIFF(now(),time)) <= 1 order by time desc;
+----+-------------+-------------+---------------------+------------+------------+----------------------------+---------------------+
| id | phone       | did         | time                | rerserved2 | rerserved3 | hour(TIMEDIFF(now(),time)) | now()               |
+----+-------------+-------------+---------------------+------------+------------+----------------------------+---------------------+
|  8 | 12122361010 | 16587143030 | 2016-02-19 21:43:18 |       NULL |       NULL |                          0 | 2016-02-19 21:45:08 |
|  7 | 18099221258 | 13065201258 | 2016-02-19 20:09:46 |       NULL |       NULL |                          1 | 2016-02-19 21:45:08 |
|  6 | 15122361010 | 14587143030 | 2016-02-19 20:09:27 |       NULL |       NULL |                          1 | 2016-02-19 21:45:08 |
+----+-------------+-------------+---------------------+------------+------------+----------------------------+---------------------+

No hay comentarios:

Publicar un comentario