1、char函数
char(current date,ISO)——转换成yyyy-mm-dd
char(current date,USA)——转换成mm/dd/yyyy
char(current date,EUR)——转换成dd.mm.yyyy
char(current date,JIS)
char(current date,LOCAL)
2、cast函数
SELECT D.* FROM wtp_pre_download AS D
WHERE cast(D.arrivetime as bigint) >= cast('20090915122359000' as bigint)
AND cast(D.arrivetime as bigint) <= cast('20090915235959999' as bigint)
3、时间函数
给定了日期、时间或时间戳,则使用适当的函数抽取出(如果适用的话)年、月、日、时、分、秒及微秒各部分:
YEAR (current timestamp)
MONTH (current timestamp)
DAY (current timestamp)
HOUR (current timestamp)
MINUTE (current timestamp)
SECOND (current timestamp)
MICROSECOND (current timestamp)
从时间戳单独抽取出日期和时间也非常简单:
DATE (current timestamp)
TIME (current timestamp)
将字符串转换成日期或时间值,可以使用:
TIMESTAMP ('2002-10-20-12.00.00.000000')
TIMESTAMP ('2002-10-20 12:00:00')
DATE ('2002-10-20')
DATE ('10/20/2002')
TIME ('12:00:00')
TIME ('12.00.00')
-----
SELECT DECIMAL(CURRENT DATE)FROM SYSIBM.SYSDUMMY1;
SELECT current date FROM sysibm.sysdummy1
SELECT current time FROM sysibm.sysdummy1
SELECT current timestamp FROM sysibm.sysdummy1
-----
使用英语(因为没有更好的术语)来执行日期和时间计算:
current date + 1 YEAR
current date + 3 YEARS + 2 MONTHS + 15 DAYS
current time + 5 HOURS - 3 MINUTES + 10 SECONDS
要计算两个日期之间相差的天数,您可以对日期作减法,例如:
days (current date) - days (date('1999-10-22'))
而以下示例描述了如何获得微秒部分归零的当前时间戳记:
CURRENT TIMESTAMP - MICROSECOND (current timestamp) MICROSECONDS
如果想将日期或时间值与其它文本相衔接,那么需要先将该值转换成字符串。为此,可以方便地使用CHAR()函数:
char(current date)
char(current time)
char(current date + 12 hours)
char(current date,ISO)——转换成yyyy-mm-dd
char(current date,USA)——转换成mm/dd/yyyy
char(current date,EUR)——转换成dd.mm.yyyy
char(current date,JIS)
char(current date,LOCAL)
2、cast函数
SELECT D.* FROM wtp_pre_download AS D
WHERE cast(D.arrivetime as bigint) >= cast('20090915122359000' as bigint)
AND cast(D.arrivetime as bigint) <= cast('20090915235959999' as bigint)
3、时间函数
给定了日期、时间或时间戳,则使用适当的函数抽取出(如果适用的话)年、月、日、时、分、秒及微秒各部分:
YEAR (current timestamp)
MONTH (current timestamp)
DAY (current timestamp)
HOUR (current timestamp)
MINUTE (current timestamp)
SECOND (current timestamp)
MICROSECOND (current timestamp)
从时间戳单独抽取出日期和时间也非常简单:
DATE (current timestamp)
TIME (current timestamp)
将字符串转换成日期或时间值,可以使用:
TIMESTAMP ('2002-10-20-12.00.00.000000')
TIMESTAMP ('2002-10-20 12:00:00')
DATE ('2002-10-20')
DATE ('10/20/2002')
TIME ('12:00:00')
TIME ('12.00.00')
-----
SELECT DECIMAL(CURRENT DATE)FROM SYSIBM.SYSDUMMY1;
SELECT current date FROM sysibm.sysdummy1
SELECT current time FROM sysibm.sysdummy1
SELECT current timestamp FROM sysibm.sysdummy1
-----
使用英语(因为没有更好的术语)来执行日期和时间计算:
current date + 1 YEAR
current date + 3 YEARS + 2 MONTHS + 15 DAYS
current time + 5 HOURS - 3 MINUTES + 10 SECONDS
要计算两个日期之间相差的天数,您可以对日期作减法,例如:
days (current date) - days (date('1999-10-22'))
而以下示例描述了如何获得微秒部分归零的当前时间戳记:
CURRENT TIMESTAMP - MICROSECOND (current timestamp) MICROSECONDS
如果想将日期或时间值与其它文本相衔接,那么需要先将该值转换成字符串。为此,可以方便地使用CHAR()函数:
char(current date)
char(current time)
char(current date + 12 hours)