posts - 89,  comments - 98,  trackbacks - 0

          一.字符操作

          1.替換指定字符

          str_replace(string1,需要替換字符,替換成字符)

          SUBSTRING(string1,,)

          二.數(shù)值操作

          三.日期操作

          getdate()
          得到當(dāng)前時(shí)間,可以設(shè)置得到各種時(shí)間格式.
          datepart(日期部分,日期)
          取指定時(shí)間的某一個(gè)部分,年月天時(shí)分秒.
          datediff(日期部分,日期1,日期2)
          計(jì)算指定的日期1和日期2的時(shí)間差多少.
          dateadd(日期部分,數(shù)值表達(dá)式,日期)
          計(jì)算指定時(shí)間,再加上表達(dá)式指定的時(shí)間長(zhǎng)度.

          --取前幾天

          'dataadd(day,-10,getdate())'

          --取時(shí)間的某一個(gè)部分
          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

          --字符串時(shí)間

          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(),108) --'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(),108)) -- '2003.11.12 11:03:41'

          --整數(shù)時(shí)間

          select convert(int,convert(char(10),getdate(),112)) -- 20031112
          select datepart(hh,getdate())*10000 + datepart(mi,getdate())*100 + datepart(ss,getdate()) -- 110646

          --時(shí)間格式 "YYYY.MM.DD HH:MI:SS" 轉(zhuǎn)換為 "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

          --當(dāng)月最后一天

          declare
          @tmpstr varchar(10)
          @mm int,
          @premm int,
          @curmmlastday varchar(10)
          begin
          select @mm=datepart(month,getdate())--當(dāng)月
          select @premm=datepart(month,dateadd(month,-1,getdate())) --上個(gè)月
          if (@mm>=1 and @mm<=8)
          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) --當(dāng)月最后一天
          end

          posted on 2006-09-20 11:43 水煮三國(guó) 閱讀(838) 評(píng)論(0)  編輯  收藏 所屬分類: Sybase
          <2006年9月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          1234567

          常用鏈接

          留言簿(4)

          隨筆分類(85)

          隨筆檔案(89)

          文章分類(14)

          文章檔案(42)

          收藏夾(37)

          java

          oracle

          Sybase

          搜索

          •  

          積分與排名

          • 積分 - 211126
          • 排名 - 265

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 萨嘎县| 沙湾县| 蓝山县| 宁城县| 中西区| 尼勒克县| 乌兰察布市| 华阴市| 营山县| 景洪市| 芜湖市| 锡林浩特市| 廊坊市| 高台县| 罗田县| 潞城市| 禹城市| 武乡县| 偃师市| 葵青区| 上蔡县| 盐池县| 海林市| 广东省| 灵台县| 汽车| 肇州县| 清涧县| 都兰县| 当涂县| 海宁市| 泰顺县| 安福县| 开封县| 临安市| 乌审旗| 横山县| 西昌市| 兰考县| 中超| 温宿县|