DateFormat

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mary mathews
    New Member
    • Apr 2008
    • 8

    DateFormat

    I want to convert a date(which is in the DDMMYYYY format) into the MMDDYYYY format in sql query.below is my query but its not working??
    Do anyone have any idea???

    declare @s char(10)
    set @s = '21/04/2008'
    select convert(char(10 ),@s,101)
  • deepuv04
    Recognized Expert New Member
    • Nov 2007
    • 227

    #2
    Originally posted by mary mathews
    I want to convert a date(which is in the DDMMYYYY format) into the MMDDYYYY format in sql query.below is my query but its not working??
    Do anyone have any idea???

    declare @s char(10)
    set @s = '21/04/2008'
    select convert(char(10 ),@s,101)
    Hi,
    Try declaring @s as datetime and set the value as '2008-04-21'

    then your query will execute currectly

    [code=sql]
    declare @s DATETIME
    --set @s = '21/04/2008'
    set @s = '2008-04-21'
    select convert(char(10 ),@s,101)

    [/code]

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      Originally posted by mary mathews
      I want to convert a date(which is in the DDMMYYYY format) into the MMDDYYYY format in sql query.below is my query but its not working??
      Do anyone have any idea???

      declare @s char(10)
      set @s = '21/04/2008'
      select convert(char(10 ),@s,101)

      Try:

      Code:
      declare @s varchar(10)
      
      set @s = '21/04/2008'
      
      select convert(varchar(20), convert(datetime, @s, 103),101)
      -- CK

      Comment

      Working...