Re: formatting a date in a sql query RRS feed

  • Question

  • User1885111408 posted


    I have a further question which I doubt you will have any problem answering...

    I am converting a date in a query and it works brilliantly, but how do I show a blank field if there is no value to return?

    The query line I am using at the moment is:

    Select CONVERT (VARCHAR(10), a.siteeol, 103) as [Site End Of Life Date]

    and the line I would normally use to show a blank field is:

    ISNULL (a,siteeol, '') as [Site End Of Life Date]

    is it possible to merge the two somehow?

    Thanks and best wishes

    Dan (UK)

    Sunday, September 9, 2018 8:34 AM

All replies

  • User2103319870 posted

    You can try with below code

    Select ISNULL(CONVERT (VARCHAR(10), a.siteeol, 103),'') as [Site End Of Life Date]
    Sunday, September 9, 2018 3:06 PM
  • User753101303 posted


    Answered but it is often suggested to convert as late as possible (ie when you are about to show this value to a user). For example here if you ever need to test this value for some reason you would have to convert it back to a DateTime). Same if you want to support multiple languages...

    Sunday, September 9, 2018 6:30 PM