select  replace(replace(replace(convert(varchar(25),getdate(),120),'-',''),':',''),' ','')

解决方案 »

  1.   

    select convert(datetime,convert(char(10),getdate(),112)+'23:59:59',120)create function testfun(@d datetime)
    returns nvarchar(100)
    as
      begin
        declare @temp nvarchar(100)
        set @temp=convert(nvarchar(100),@d,120)
        set @temp=replace(@temp,'-','')
        set @temp=replace(@temp,':','')
        set @temp=replace(@temp,' ','')
        return(@temp)
      end
    go
    print ralph_test.dbo.testfun(getdate())drop function testfun
      

  2.   

    xluzhong(打麻将一缺三,咋办?) 
    select convert(datetime,convert(char(10),getdate(),112)+'23:59:59',120)
    这句得到的有毫秒的.如
    2005-01-28 23:59:59.000请问怎样把毫秒去掉呢?:),谢谢了
      

  3.   

    你说的,我只知道用字符串连接符来得到
    我查看了帮助,好像没有那种日期格式是你所要的
    可以用Year,Month,Day函数得到年,月,日再连起来
      

  4.   

    2005-01-28 23:59:59.000请问怎样把毫秒去掉呢?:),谢谢了
    ---------------------------------
    可以用函数Left去掉,如Left('2005-01-28 23:59:59.000',19)
    或用CAST(CONVERT)转换成字符时去掉,如cast(日期字段 as char(19)),convert(char(19),日期字段,120)
      

  5.   

    奇怪了,用了个过程,输出格式又变了create proc test1
    @test char(30) output
    as
     select @test=convert(datetime,convert(char(10),getdate(),112)+'11:59:59',120)
     print @test
    go变成:
    01 28 2005 11:59AM各位大哥帮帮忙了,真奇怪