Switching from YYYYMMDD to MMDDYYYY

  • Hi,

    I'm trying to figure this out in SQL Server.  I imported an Oracle table with dates in YYYYMMDD and these dates are stored in a Char field.  I want to convert this Char field to a datetime with the format mm/dd/yyyy.

    I can't switch the data field to datetime because it will return an error message.  I've tried the convert function but I believe I'm missing a step.  Need assistance please.

    This is what I have so far:

     

    SELECT datelatestpaym,CONVERT(datetime, datelatestpaym, 101) AS newpaydate FROM tblname

    returns: 2000-05-22 00:00:00.000

    Thanks,

    Joe

  • I get the desired result when I try this.  Add this extra step and see what you are presented. 

    SELECT CONVERT( varchar, CONVERT( datetime, '20050522'), 101) 

    I wasn't born stupid - I had to study.

  • Thank You,

    I got my expected results. 

    It's literally been years since I've done any type of date formatting.  I try to keep my toolbox up to date but I feel I've failed miserably at this.

    Once again thanks

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

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