Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2006
    Posts
    28

    Unanswered: will varchar automatic convert into datetime ?

    hi, good day, if i have a table as follow:
    Code:
    Create table test
    (
       student_name varchar(20),
       student id varchar(20),
       register_dt varchar(50)
    )
    and insert data like

    Code:
    insert into test values('rebecca','0001','2006-08-08 12:15:03')
    after all , i would like to query the data and insert into another table say data_tbl where it define as follow
    Code:
    Create table data_tbl
    (
    
       student_name varchar(20),
       student id varchar(20),
       register_dt datetime
    )
    would the test table regiter_dt auto convert into datetime format or we need to convert it before insert into data_tbl table?

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Those dates that are "real" dates will convert fine. If you are ONLY storing dates I would set register_dt as SmallDateTime. You would be amazed how many times we get people struggling because some "invalid" data got into varchar fields but they were supposed to be dates\ numbers.

    If you have to store as varchar then at least put in all the necessary constraints to ensure they are always valid dates.

    Minot thing but if register date doesn't need to be accurate to the second you could make do with smalldatetime.

    HTH
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Jul 2006
    Posts
    22
    for future references like this, check Books OnLine - "Cast and Convert" help, there are a chart in wich you can view all types of conversions between data types. - There are implicit conversion between datetime and varchar.

  4. #4
    Join Date
    Jul 2006
    Posts
    28
    thank you for clear my doubt

Posting Permissions

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