日期函数和字符串函数.doc_第1页
日期函数和字符串函数.doc_第2页
日期函数和字符串函数.doc_第3页
日期函数和字符串函数.doc_第4页
日期函数和字符串函数.doc_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

日期函数和字符串函数日期函数和字符串函数.txt心脏是一座有两间卧室的房子,一间住着痛苦,一间住着快乐。人不能笑得太响,否则会吵醒隔壁的痛苦。日期函数getdate()得到当前时间,可以设置得到各种时间格式.datepart(日期部分,日期)取指定时间的某一个部分,年月天时分秒.datediff(日期部分,日期1,日期2)计算指定的日期1和日期2的时间差多少.dateadd(日期部分,数值表达式,日期)计算指定时间,再加上表达式指定的时间长度.-取时间的某一个部分select datepart(yy,getdate() -yearselect datepart(mm,getdate() -monthselect datepart(dd,getdate() -dayselect datepart(hh,getdate() -hourselect datepart(mi,getdate() -minselect datepart(ss,getdate() -sec-取星期几set datefirst 1select datepart(weekday,getdate() -weekday-字符串时间select getdate() - 03/11/12select convert(char,getdate(),101) - 09/27/2003select convert(char,getdate(),102) - 2003.11.12select convert(char,getdate(),103) - 27/09/2003select convert(char,getdate(),104) - 27.09.2003select convert(char,getdate(),105) - 27-09-2003select convert(char,getdate(),106) - 27 Sep 2003select convert(char,getdate(),107) -Sep 27, 2003select convert(char,getdate(),108) -11:16:06select convert(char,getdate(),109) -Sep 27 2003 11:16:28:746AMselect convert(char,getdate(),110) -09-27-2003select convert(char,getdate(),111) -2003/09/27select convert(char,getdate(),112) -20030927select rtrim(convert(char,getdate(),102)+ +(convert(char,getdate(),108) - 2003.11.12 11:03:41-整数时间select convert(int,convert(char(10),getdate(),112) - 20031112select datepart(hh,getdate()*10000 + datepart(mi,getdate()*100 + datepart(ss,getdate() - 110646-时间格式 YYYY.MM.DD HH:MI:SS 转换为 YYYYMMDDHHMISSdeclare 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 tmpselect tmp1=convert(char(10),datepart(hh,a)*10000 + datepart(mi,a)*100 + datepart(ss,a)select tmp1select tmp=tmp+tmp1select tmp-当月最后一天declaretmpstr varchar(10)mm int,premm int,curmmlastday varchar(10)beginselect mm=datepart(month,getdate()-当月select premm=datepart(month,dateadd(month,-1,getdate() -上个月if (mm=1 and mm=9 and mm0 转换函数convert此函数把值从一种类型改变成另一种类型convert(datetype (length),expression)select Advance=+convert(char(12),advance) from titles日期转换convert(datetype(length),expression,format)format指定将日期转换为什么格式,有以下值:没有世纪 有世纪 转换字符串中日期格式 0 or 100 mon dd yyy hh:miAM(or PM)1 101 mm/dd/yy2 102 yy.mm.dd3 103 dd/mm/yy4 104 dd.mm.yy5 105 dd-mm-yy6 106 dd mon yy7 107 mon dd,yy8 108 hh:mm:ss 9 or 109 mon dd,yyyy hh:mi:ss:mmmAM(or PM)10 110 mm-dd-yy11 111 yy/mm/dd12 112 yymmdd 系统函数函数 定义访问和安全性信息host_id() 客户进程的当前主机进程ID号host_name() 客户进程的当前主计算机名suser_id(login_name) 用户的SQL Server ID号suser_name(server_user_id) 用户的SQL Server登录名user_id(name_in_db) 用户在数据库中的ID号user_name(user_id) 用户在数据库中的名字user 用户在数据库中的名字show_role() 用户的当前活动角色数据库和对象信息db_id(db_name) 数据库ID号db_name(db_id) 数据库名object_id(objname) 数据库对象ID号object_name(obj_id) 数据库对象号col_name(obj_id,col_id) 对象的栏名col_length(objname,colname) 栏的长度index_col(objname,index_id,key#) 已索引的栏名valid_name(char_expr) 若char_expr不是有效标识符,则返回0数据函数datalength(expression) 按字节返

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论