函数用法??
datediff() ,dateadd() 问题点数:100、回复次数:5Top
1 楼xiaotao0432(白开水)回复于 2003-12-01 17:55:31 得分 0
上面两个函数怎么用呀,谢谢,初学sybaseTop
2 楼lilygy5(我爱oracle)回复于 2003-12-01 19:51:15 得分 50
datediff( datepart, date1, date2 )
Returns date2 - date1, measured in the specified date part. For example, the following statement displays the value 102.
SELECT datediff( month, '1987/05/02', '1995/11/15')
dateadd( datepart, numeric_expression, date )
Returns the date produced by adding the specified number of the specified date parts to the date. The numeric_expression can be any numeric type; the value is truncated to an integer. For example, the following statement displays 1995-11-02 00:00:00.000.
SELECT dateadd( month, 102, '1987/05/02'Top
3 楼lilygy5(我爱oracle)回复于 2003-12-01 19:53:41 得分 0
你装了sybase吧,里面的 sql anywhere user's guide 里面有这些的,详细可以到那里去查Top
4 楼xiaoliaoyun(流浪的云)回复于 2003-12-01 20:41:41 得分 50
DateDiff(日期元素,日期,日期) 作用:返回两个日期的差值并转换为指定日期元素的形式
DateAdd(日期元素,数值,日期) 作用: 将日期元素加上日期后产生新的日期
其中日期元素有year(缩写为yy),month(缩写为mm),day(dd),dayofyear(dy),week(wk),weekday(dw),hour(hh),minute(mi),quarter(qq),second(ss),millisecond(ms)
例如:在查询分析器里输入:
DECLARE @starttime datetime --开始时间
DECLARE @endtime datetime --结束时间
DECLARE @totalhours int --开始时间到结束时间的总小时数(若开始时间大于结束时
--间,则返回负值)
DECLARE @totalminutes int --开始时间到结束时间的总分钟数
SET @starttime='2000/1/1'
SET @endtime='2000/1/2'
SET @totalhours=DateDiff(hh,@starttime,@endtime)
SET @totalminutes=DateDiff(mi,@starttime,@endtime)
SELECT 'total hours'=@totalhours, 'total minutes'=@totalminutes
其它的多看看帮助,里面很详细的.
Top
5 楼xiaoliaoyun(流浪的云)回复于 2003-12-01 20:43:14 得分 0
返回结果为
total hours total minutes
24 1440Top




