2013-03-06 107 views
0

我有减去从到期时间拿出数天的原购买时下面的查询减去:MySQL的 - 截断日期/时间,相互

select date(expires_dtime) - date(original_purchase_dtime) 
from sl_player_subscription 
where player_uuid = '9c61411c-54b4-45bd-8d07-264b1c2e4249' 

player_uuid that = '9c61411c-54b4-45bd-8d07-264b1c2e4249'有一种原始的购买的2013-03-06 11:36:46时间和2013-04-05 12:36:46.

到期时间我想输出改为“30”,这是购买时间和到期时间之间的天数,而是输出为99。有什么建议?

+2

你尝试'DATEDIFF'功能? https://dev.mysql.com/doc/refman/5.5/zh-TW/date-and-time-functions.html#function_datediff – 2013-03-06 20:42:50

+0

我现在做了。非常感谢你! – Americo 2013-03-06 20:44:10

+0

欢迎您:) – 2013-03-06 20:45:24

回答

4

您可以使用DATEDIFF

SELECT DATEDIFF('2013-04-05 12:36:46', '2013-03-06 11:36:46') 

结果

30

使用您的列:

SELECT DATEDIFF(expires_dtime, original_purchase_dtime) 

See the demo

DATEDIFF()回报表达式1 - 表达式2表示为从一个日期至另一个在天的值。 expr1 and expr2是日期或日期和时间表达式。计算中只使用数值的日期部分。

Documentation: Date and Time functions