I want to insert a Date in dd/mm/yy format to a ta

Results 1 to 3 of 3

Thread: I want to insert a Date in dd/mm/yy format to a ta

  1. #1
    Join Date
    Dec 1969

    Default I want to insert a Date in dd/mm/yy format to a ta

    Table Name : tb_article<BR>FieldName Datatype Size <BR>SrNo varchar 10 <BR>Name varchar 35<BR>Email varchar 35<BR>Article varchar 500 <BR>ADate datetime 8<BR><BR>insert into tb_article values(&#039;1&#039;,&#039;test&#039;,&#039;test&# 039;,&#039;test&#039;,convert(char(8),getdate(),3) )<BR>Above Statement is giving me Error<BR>Server: Msg 242, Level 16, State 3, Line 1<BR>The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.<BR>The statement has been terminated.<BR><BR>Just give me the Right statement to insert the value of the Date in dd/mm/yy format.

  2. #2
    Join Date
    Dec 1969

    Default RE: I want to insert a Date in dd/mm/yy format to

    Look old chap, I&#039;ll keep this terribly simple. When those bright chaps put together the data types, they assumed that people wouldn&#039;t want to format the contents. One example my mother just reminded me of is that you can&#039;t have insert text in a varchar column as bold, italics or upside down. Awful shame, I know but there you go.<BR>The key to this conundrum (with me so far) is to put the date in just as a (you guessed it) date and then when you retrieve the date through a SELECT statement (ever so useful those SELECT statements), you format the blighter through a CONVERT function. Hope this helps. Mother needs a hand with some Java so I&#039;ll be back anon to answer more queries. Tally ho!

  3. #3
    Join Date
    Dec 1969

    Default Wrong way round

    You can not affect the storage format for a datetime value. Insert it as a datetime value and do the required formatting when you retrieve the data.<BR><BR>insert into tb_article values(&#039;1&#039;,&#039;test&#039;,&#039;test&# 039;,&#039;test&#039;,getdate())<BR><BR>Datetime values are stored as numeric values and not as strings.

Posting Permissions

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