Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2013
    Posts
    8

    Question Unanswered: Convert CHAR or String to Date

    I have a date in CHAR as 1/1/2011 and I need it to be a datetime variable. How do I convert it? The field name is StartDt. I tried:
    Convert(DateTime, StartDt, 101)
    and that didn't work. Any suggestions?

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    The answer depends on several things, but I'd start by trying:
    Code:
    Cast(StartDt AS DATETIME)
    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Dec 2013
    Posts
    8
    I'm getting error 1292, where it says it is an incorrect datetime value

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Then I'd try using the MySQL Str_To_Date() function and convert the strings to dates. Note that if the string is not a valid date, then Str_To_Date() will return a NULL value, which I'd bet that you'll have to handle.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Pat P's suggestion makes far more sense than my approach, so Im hiding it....
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    Join Date
    Dec 2013
    Posts
    8
    thank you both. I'm going to try to get the data handed off in a better format. If all else fails, I'll come back. thank you.

Tags for this Thread

Posting Permissions

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