Professional Web Applications Themes

Newbie date convertion question - Microsoft SQL / MS SQL Server

I need to convert a string/character field into a date field. The string/character field is in the following format: 20010525 and i need to convert this into a date field, ideally smalldatetime data type. I can convert the string/character field into a numeric field if that make the convertion easier. So any help would be great. Thanks...

  1. #1

    Default Newbie date convertion question

    I need to convert a string/character field into a date
    field. The string/character field is in the following
    format:

    20010525

    and i need to convert this into a date field, ideally
    smalldatetime data type. I can convert the
    string/character field into a numeric field if that make
    the convertion easier. So any help would be great.

    Thanks
    Sandip Guest

  2. #2

    Default Re: Newbie date convertion question

    Do:

    SELECT CAST('20010525' AS SMALLDATETIME)

    --
    - Anith
    ( Please reply to newsgroups only )


    Anith Guest

  3. #3

    Default Re: Newbie date convertion question

    Sandip,

    CREATE TABLE dtestring
    (
    dte VARCHAR(20)
    )
    GO
    INSERT dtestring VALUES('20010525')
    GO
    SELECT CAST(dte AS SMALLDATETIME) FROM dtestring


    --
    Dinesh.
    SQL Server FAQ at
    http://www.tkdinesh.com

    "Sandip" <com> wrote in message
    news:105d01c361bb$60df2040$gbl... 


    Dinesh.T.K Guest

  4. #4

    Default Re: Newbie date convertion question

    SELECT CONVERT(smalldatetime, '20010525', 112)




    "Sandip" <com> wrote in message
    news:105d01c361bb$60df2040$gbl... 


    Aaron Guest

  5. #5

    Default Re: Newbie date convertion question

    Is this what you are looking for ?

    SELECT CAST('20010525' AS SMALLDATETIME)

    HTH

    "Sandip" <com> wrote in message
    news:105d01c361bb$60df2040$gbl... 


    Amy Guest

Similar Threads

  1. Newbie date from DB question
    By ghouser in forum Coldfusion Database Access
    Replies: 4
    Last Post: March 17th, 04:56 PM
  2. Replies: 5
    Last Post: December 3rd, 10:44 AM
  3. newbie: day number in year to gregorian date?
    By thordivel in forum PHP Development
    Replies: 0
    Last Post: October 13th, 10:42 AM
  4. converting date into database date format(newbie)
    By Binay Agarwal in forum PHP Development
    Replies: 2
    Last Post: August 29th, 01:09 PM
  5. String convertion to date
    By L in forum Microsoft SQL / MS SQL Server
    Replies: 3
    Last Post: July 18th, 09:21 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139