星期三, 9月 23, 2009

MS SQL DATEDIFF(計算兩時間差)

使用Convert、DATEDIFF 函數求得時間差
SELECT design_product_comment_id, design_product_comment_pid, design_product_comment_username, design_product_comment_text,
design_product_comment_category,
CONVERT(varchar(4), DATEDIFF(day, design_product_comment_date, GETDATE())) AS Days, CONVERT(varchar(4), DATEDIFF(hour, design_product_comment_date, GETDATE()) % 24) AS Hours,
CONVERT(varchar(4), DATEDIFF(minute, design_product_comment_date, GETDATE()) % 60) AS Mins
FROM design_product_comment
WHERE (design_product_comment_pid = @dpid) AND (design_product_comment_category = @cid)"

沒有留言:

張貼留言

留個話吧:)

其他你感興趣的文章

Related Posts with Thumbnails