locked
CONVERT Date RRS feed

  • Question

  • Is it possible to convert this date 2009-05-25 00:00:00:000 (DATETIME DataType) To 250509 (VARCHAR will do)
    Wednesday, June 3, 2009 11:49 PM

Answers

  • Parry2k was close...

    To get it in ddmmyy format, use REPLACE(CONVERT(varchar(10), MyDate, 3), '/', '')

    --Brad
    • Marked as answer by 中國風MVP Friday, June 5, 2009 8:21 AM
    Thursday, June 4, 2009 12:03 AM
  • select
        replace(convert(varchar(10),cast('2009-05-25 00:00:00:000' as datetime),3),'/','') as Date1,
        replace(convert(varchar(10),cast('2009-05-25 00:00:00:000' as datetime),4),'.','') as Date2,
        replace(convert(varchar(10),cast('2009-05-25 00:00:00:000' as datetime),5),'-','') as Date3

    You use the convert function

    ROY WU(吳熹)
    • Marked as answer by 中國風MVP Friday, June 5, 2009 8:19 AM
    Thursday, June 4, 2009 2:21 AM

All replies

  • convert(nvarchar, yourdatefield, 112)
    Wednesday, June 3, 2009 11:59 PM
  • Parry2k was close...

    To get it in ddmmyy format, use REPLACE(CONVERT(varchar(10), MyDate, 3), '/', '')

    --Brad
    • Marked as answer by 中國風MVP Friday, June 5, 2009 8:21 AM
    Thursday, June 4, 2009 12:03 AM
  • or try this

    replace(convert(nvarchar, getdate(), 103),'/', '')
    Thursday, June 4, 2009 12:06 AM
  • Thanks folks, that works.

    Cheers.
    Thursday, June 4, 2009 12:19 AM
  • Brad he need to give the convert style i.e. 103 so that return date is ddmmyyyy and if he doesn't want century then style value will be 3

    cheers!!!
    Thursday, June 4, 2009 12:20 AM
  • Brad he need to give the convert style i.e. 103 so that return date is ddmmyyyy and if he doesn't want century then style value will be 3

    cheers!!!

    Yes, convert style 3 was what I used in my post... he seemed to indicate no century in his original post.


    --Brad
    Thursday, June 4, 2009 12:52 AM
  • select
        replace(convert(varchar(10),cast('2009-05-25 00:00:00:000' as datetime),3),'/','') as Date1,
        replace(convert(varchar(10),cast('2009-05-25 00:00:00:000' as datetime),4),'.','') as Date2,
        replace(convert(varchar(10),cast('2009-05-25 00:00:00:000' as datetime),5),'-','') as Date3

    You use the convert function

    ROY WU(吳熹)
    • Marked as answer by 中國風MVP Friday, June 5, 2009 8:19 AM
    Thursday, June 4, 2009 2:21 AM