Results 1 to 4 of 4
  1. #1
    Join Date
    May 2005
    Posts
    119

    Unanswered: Formatting Dates as YYYY/MM/DD for a particular query

    Anyone know how to format dates from 10/3/05 to 2005/10/03 in a query?

    The only way I know is (cast(year(srecordeddate) as char(4)))+ cast('/'as char) + cast (month(srecordeddate) as char(2)).... Which seems so rediculous. There's gotta be a better way!

  2. #2
    Join Date
    Sep 2005
    Posts
    161
    select convert(varchar(10), getdate(), 111)

  3. #3
    Join Date
    Dec 2002
    Posts
    1,245
    Quote Originally Posted by Krista327
    Anyone know how to format dates from 10/3/05 to 2005/10/03 in a query?

    The only way I know is (cast(year(srecordeddate) as char(4)))+ cast('/'as char) + cast (month(srecordeddate) as char(2)).... Which seems so rediculous. There's gotta be a better way!
    With the caveat that it's almost ALWAYS better to handle formatting on the client side, you might try:

    Convert(varchar(10), [YourDate], 120)

    Regards,

    hmscott
    Have you hugged your backup today?

  4. #4
    Join Date
    May 2005
    Posts
    119
    Quote Originally Posted by cascred
    select convert(varchar(10), getdate(), 111)
    Thanks! You've bailed me out of another toughee...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •