Format for six character date

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • robboll

    Format for six character date

    Using SQL Server 2000 in a view, if the data is Char and six
    characters like: 081564

    How do I convert it to a date that looks like: 08/15/1964 and is a
    date.

    I am trying:

    CONVERT (varchar, SUBSTRING(Col00 5, 1, 2) + '/' + SUBSTRING(Col00 5, 3,
    2) + '/' + SUBSTRING(Col00 5, 5, 2), 112)

    but it returns 08/15/64. Anyone tell me what I'm doing wrong.

    Thanks in advance!

    RBolling

  • Shiju Samuel

    #2
    Re: Format for six character date

    This should work

    select
    CONVERT (varchar, cast(SUBSTRING( '081564' , 1, 2) +
    '/' + SUBSTRING('0815 64' , 3,
    2) + '/' + SUBSTRING('0815 64' , 5, 2) as datetime), 101)

    -
    Shiju


    On Sep 4, 10:56 am, robboll <robb...@hotmai l.comwrote:
    Using SQL Server 2000 in a view, if the data is Char and six
    characters like: 081564
    >
    How do I convert it to a date that looks like: 08/15/1964 and is a
    date.
    >
    I am trying:
    >
    CONVERT (varchar, SUBSTRING(Col00 5, 1, 2) + '/' + SUBSTRING(Col00 5, 3,
    2) + '/' + SUBSTRING(Col00 5, 5, 2), 112)
    >
    but it returns 08/15/64. Anyone tell me what I'm doing wrong.
    >
    Thanks in advance!
    >
    RBolling

    Comment

    Working...