要使當前時間或當前時間戳記調(diào)整到 GMT/CUT,則把當前的時間或時間戳記減去當前時區(qū)寄存器: current time - current timezone current timestamp - current timezone
給定了日期、時間或時間戳記,則使用適當?shù)暮瘮?shù)可以單獨抽取出(如果適用的話)年、月、日、時、分、秒及微秒各部分: YEAR (current timestamp) MONTH (current timestamp) DAY (current timestamp) HOUR (current timestamp) MINUTE (current timestamp) SECOND (current timestamp) MICROSECOND (current timestamp)
因為沒有更好的術(shù)語,所以您還可以使用英語來執(zhí)行日期和時間計算: current date + 1 YEAR current date + 3 YEARS + 2 MONTHS + 15 DAYS current time + 5 HOURS - 3 MINUTES + 10 SECONDS
從時間戳記單獨抽取出日期和時間也非常簡單: DATE (current timestamp) TIME (current timestamp)
而以下示例描述了如何獲得微秒部分歸零的當前時間戳記:
CURRENT TIMESTAMP - MICROSECOND (current timestamp) MICROSECONDS
CREATE FUNCTION daysinyear(yr INT) RETURNS INT RETURN (CASE (mod(yr, 400)) WHEN 0 THEN 366 ELSE CASE (mod(yr, 4)) WHEN 0 THEN CASE (mod(yr, 100)) WHEN 0 THEN 365 ELSE 366 END ELSE 365 END END)@