I got a problem with an sql statement:
In a table there is a field of type varchar. That field ,called datearrival, contains human readable dates such as "March 4th 2004" (no quotes).
I want to select all items for which the number of days between datearrival and the current date is > 50.
So I try the following sql statement:
1. "select id from item where datediff(dd,datearrival,getdate())>50"
Sql Server complains about not being able to convert between from varchar to datetime. How can I correct this problem.
I tried manually entering the following statement and it happens to work:
2. "select id from item where datediff(dd,'March 4 2004',getdate())>50"
Since this worked, I thought this means i may need to append single quotes to subdescription3 in my original statement, in order to get it to work. So I tried:
3. "select id from item where datediff(dd,''''subdescription3'''',getdate())>50"
but that does not work...So I'm stuck here. Is there an easy way to solve my problem??
In a table there is a field of type varchar. That field ,called datearrival, contains human readable dates such as "March 4th 2004" (no quotes).
I want to select all items for which the number of days between datearrival and the current date is > 50.
So I try the following sql statement:
1. "select id from item where datediff(dd,datearrival,getdate())>50"
Sql Server complains about not being able to convert between from varchar to datetime. How can I correct this problem.
I tried manually entering the following statement and it happens to work:
2. "select id from item where datediff(dd,'March 4 2004',getdate())>50"
Since this worked, I thought this means i may need to append single quotes to subdescription3 in my original statement, in order to get it to work. So I tried:
3. "select id from item where datediff(dd,''''subdescription3'''',getdate())>50"
but that does not work...So I'm stuck here. Is there an easy way to solve my problem??