2013-03-06 111 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