与mysql表的日期和时间差异 [英] date and time difference from mysql table

查看:111
本文介绍了与mysql表的日期和时间差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将三个基本时间戳和时间存储到我的数据库表中,格式如下 -



I have stored three essential timestamp and time into my database table, format as follows-

mysql> select receivedtime, requesttime, sla from table;
+---------------------+---------------------+----------+
| receivedtime        | requesttime         | sla      |
+---------------------+---------------------+----------+
| 2013-05-26 22:37:04 | 2013-05-26 12:37:04 | 02:59:59 |
| 2013-05-26 14:36:44 | 2013-05-21 12:39:09 | 72:00:00 |
+---------------------+---------------------+----------+
2 rows in set (0.00 sec)



我需要放几个条件如下



差异=(收到时间 - 请求时间);




I need to put few condition like below

difference = (receivedtime - requesttime);

if [difference <= sla]
{
   show meet
} else {
   show don't meet
}





legend

receivedtime [timestamp]因为天数

请求时间[timestamp]因为天数

sla [时间]因为小时



需要帮助!



legend:
receivedtime [timestamp] as because days
requesttime [timestamp] as because days
sla [time] as because hour

Need Help !

推荐答案

警告 - 我可以''此刻转到我的MySQL实例,因此您可能无法复制和粘贴这...



尝试从这样的数据库中选择...

Warning - I can''t get to my MySQL instance at the moment so you may not be able to just copy&paste this ...

Try selecting from your database like this ...
select TIMESTAMPDIFF(SECOND, receivedtime, requesttime) as difference, TIME_TO_SEC(sla) as slasecs from table



然后你可以做你的


and then you can do your

if [difference <= sla]
{
   show meet
} 
else 
{
   show don't meet
}


这篇关于与mysql表的日期和时间差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆