locked
add zero to month and day in tsql RRS feed

  • Question

  • User1439346456 posted

    hi guys

    how to add zero to single month and day in tsql

    2010-3-9 convert to 2010-03-09

    thanks

    Sunday, October 2, 2016 3:54 PM

Answers

  • User475983607 posted

    If the coumn is a datetime type then use the convert function to format date as you like.
    https://msdn.microsoft.com/en-us/library/ms187928.aspx
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 2, 2016 5:31 PM
  • User-1716253493 posted

    Seem like the value is varchar, cast it first to date datatype

    CAST(colname as Date)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 3, 2016 12:46 AM

All replies

  • User475983607 posted

    If the coumn is a datetime type then use the convert function to format date as you like.
    https://msdn.microsoft.com/en-us/library/ms187928.aspx
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 2, 2016 5:31 PM
  • User-1716253493 posted

    Seem like the value is varchar, cast it first to date datatype

    CAST(colname as Date)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 3, 2016 12:46 AM