How to I convert this code from Oracle to SQL Server?

  • I haven't been able to successfully update this code.

    Oracle
    REPLACE(TO_CHAR(PRAC.DATE_OF_BIRTH,'MM-DD-YYYY'),'-','/') AS DOB,

    SQL Server
    REPLACE(CAST(PRAC.DATE_OF_BIRTH AS DATE ['MM-DD-YYYY']),'-','/') AS DOB,

    Thanks in advance for any assistance.

  • kawi6rr - Tuesday, August 1, 2017 5:10 PM

    I haven't been able to successfully update this code.

    Oracle
    REPLACE(TO_CHAR(PRAC.DATE_OF_BIRTH,'MM-DD-YYYY'),'-','/') AS DOB,

    SQL Server
    REPLACE(CAST(PRAC.DATE_OF_BIRTH AS DATE ['MM-DD-YYYY']),'-','/') AS DOB,

    Thanks in advance for any assistance.

    It depends on what the data type is for DATE_OF_BIRTH.
    Generally you can use something like:
    SELECT REPLACE(CONVERT (varchar(10), GETDATE(), 110), '-', '/') AS DOB
    which would return today's date as 08/01/2017

    Sue

  • Yes, or return dates as dates, and if you need to make it all look pretty, do that in the presentation layer.

    John

  • Or you could remove the REPLACE altogether with a different format code.
    SELECT CONVERT (char(10), GETDATE(), 101) AS DOB

    But I agree with leaving the formatting in the presentation layer and keep the dates as dates for as long as possible.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply