www.webdeveloper.com
Results 1 to 3 of 3

Thread: I need help converting a data field to datetime from a varchar(10)

  1. #1
    Join Date
    Mar 2006
    Posts
    56

    I need help converting a data field to datetime from a varchar(10)

    I have this statement that I need to execute:

    DELETE FROM callcenter..tRecipQueue WHERE DATEDIFF(dd, expiration_date, GetDate()) > 368

    Of course it doesn't work because expiration_date is a varchar data type, which contains MM/DD/YYYY value. How can I efficiently cast or convert that data, so my sp won't complain about this error?

    The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
    The statement has been terminated.

    Thanks!

  2. #2
    Join Date
    Mar 2006
    Posts
    56
    Thank you for confirming that it was data error!

    Wow, after analyzing the data I figured it out! On my forms I was not validating the dates properly, so some how three dates were passed as 02/29/2007, 02/30/2008, which are not valid! I have three textboxes each for MM/DD/YYYY, I guess before I do an insert/update to the column I should do a validation.

    I set a string variable that takes each textbox value and I string them together.

    THanks!

  3. #3
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    Couldn't you convert it into a date type when it goes into the database?
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles