date problem

  • How can i filter date from this

    '16/Aug/2004 1:05:00 PM'

    like '16/Aug/2004'  i tried this one

    SELECT DATEPART(m, getdate()), DATEPART(d, getdate()), DATEPART(yy, getdate())
    but i dont like this, suggest me anything different
  • If it's ok to get the month as numeric, you can do this..

    declare @date datetime
    set @date = '16/Aug/2004 1:05:00 PM'
    select convert(varchar, @date, 103) as formattedDate
    
    Result
    16/08/2004
    

    ..else you can play around with the different "styles" for display..







    **ASCII stupid question, get a stupid ANSI !!!**

  • Here's the same thing with '106'..

    declare @date datetime
    set @date = '16/Aug/2004 1:05:00 PM'
    select convert(varchar, @date, 106) as formattedDate
    
    Result
    16 Aug 2004
    







    **ASCII stupid question, get a stupid ANSI !!!**

  • As per msdn

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ca-co_2f3o.asp

     

    DD/MON/YYY format is not possible by convert function. You need to look for other alternatives.

  • If you must use a non standard date format, then:

    declare @date datetime

    set @date = '16/Aug/2004 1:05:00 PM'

    select convert(varchar,CAST(REPLACE(@date,'/',' ') AS datetime), 112) AS ISO

    select convert(varchar,CAST(REPLACE(@date,'/',' ') AS datetime), 120) AS [ODBC canonical]

    If you use ISO or ODBC formats you will be better off

    Andy

  • declare @date datetime

    set @date = '16/Aug/2004 1:05:00 PM'

    select convert(varchar(11),@date, 113) AS ISO

    with in the andy suggestion itself if we specify the no of char we want to get from the date just specify in the varchar ....

    Balram

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply