ASE 如何获得指定时间段内的随机时间?
时间:2010-12-21
来源:互联网
比如
每天 23:00-23:59:59 时间范围内
取得一个随机时间
谢谢
每天 23:00-23:59:59 时间范围内
取得一个随机时间
谢谢
作者: piml_lv 发布时间: 2010-12-21
- 日期函数
-
- getdate()
-
- 得到当前时间,可以设置得到各种时间格式.
-
- datepart(日期部分,日期)
-
- 取指定时间的某一个部分,年月天时分秒.
-
- datediff(日期部分,日期1,日期2)
-
- 计算指定的日期1和日期2的时间差多少.
-
- dateadd(日期部分,数值表达式,日期)
-
- 计算指定时间,再加上表达式指定的时间长度.
-
- --取时间的某一个部分
-
- select datepart(yy,getdate()) --year
-
- select datepart(mm,getdate()) --month
-
- select datepart(dd,getdate()) --day
-
- select datepart(hh,getdate()) --hour
-
- select datepart(mi,getdate()) --min
-
- select datepart(ss,getdate()) --sec
-
- --取星期几
-
- set datefirst 1
-
- select datepart(weekday,getdate()) --weekday
-
- --字符串时间
-
- select getdate() -- '03/11/12'
-
- select convert(char,getdate(),101) -- '09/27/2003'
-
- select convert(char,getdate(),102) -- '2003.11.12'
-
- select convert(char,getdate(),103) -- '27/09/2003'
-
- select convert(char,getdate(),104) -- '27.09.2003'
-
- select convert(char,getdate(),105) -- '27-09-2003'
-
- select convert(char,getdate(),106) -- '27 Sep 2003'
-
- select convert(char,getdate(),107) --'Sep 27, 2003'
-
- select convert(char,getdate(),10 --'11:16:06'
-
- select convert(char,getdate(),109) --'Sep 27 2003 11:16:28:746AM'
-
- select convert(char,getdate(),110) --'09-27-2003'
-
- select convert(char,getdate(),111) --'2003/09/27'
-
- select convert(char,getdate(),112) --'20030927'
-
- select rtrim(convert(char,getdate(),102))+' '+(convert(char,getdate(),10) -- '2003.11.12 11:03:41'
-
- --整数时间
-
- select convert(int,convert(char(10),getdate(),112)) -- 20031112
-
- select datepart(hh,getdate())*10000 + datepart(mi,getdate())*100 + datepart(ss,getdate()) -- 110646
-
- --时间格式 "YYYY.MM.DD HH:MI:SS" 转换为 "YYYYMMDDHHMISS"
-
- declare @a datetime,@tmp varchar(20),@tmp1 varchar(20)
-
- select @a=convert(datetime,'2004.08.03 12:12:12')
-
- select @tmp=convert(char(10),@a,112)
-
- select @tmp
-
- select @tmp1=convert(char(10),datepart(hh,@a)*10000 + datepart(mi,@a)*100 + datepart(ss,@a))
-
- select @tmp1
-
- select @tmp=@tmp+@tmp1
-
- select @tmp
-
- --当月最后一天
-
- declare
-
- @tmpstr varchar(10)
-
- @mm int,
-
- @premm int,
-
- @curmmlastday varchar(10)
-
- begin
-
- select @mm=datepart(month,getdate())--当月
-
- select @premm=datepart(month,dateadd(month,-1,getdate())) --上个月
-
- if (@mm>=1 and @mm<=
-
- select @tmpstr=convert(char(4),datepart(year,getdate()))+'.0'+convert(char(1),datepart(month,dateadd(month,1,getdate())))+'.'+'01'
-
- else if (@mm>=9 and @mm<=11)
-
- select @tmpstr=convert(char(4),datepart(year,getdate()))+'.'+convert(char(2),datepart(month,dateadd(month,1,getdate())))+'.'+'01'
-
- else
-
- select @tmpstr=convert(char(4),datepart(year,dateadd(year,1,getdate())))+'.0'+convert(char(1),datepart(month,dateadd(month,1,getdate())))+'.'+'01'
-
- select @curmmlastday=convert(char(10),dateadd(day,-1,@tmpstr),102) --当月最后一天
-
- end
看看能不能帮到你!
作者: wfcjz 发布时间: 2010-12-23
select "23:"+convert(varchar(2),convert(int,60*rand()))+":"+convert(varchar(2),convert(int,60*rand()))
作者: Eisen 发布时间: 2010-12-23
再来个看起来形式更简单的。
select convert(varchar,dateadd(ss,rand()*3600,'23:00:00'),8)
select convert(varchar,dateadd(ss,rand()*3600,'23:00:00'),8)
作者: andkylee 发布时间: 2010-12-23
还是你这个漂亮……

作者: Eisen 发布时间: 2010-12-23
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28