Jump to content

DATETIME conversion


Naya

Recommended Posts

Hi,

 

I am having trouble with this error:

PHP Warning: (null)(): Invoke() failed: Exception occurred. Source: Microsoft OLE DB Provider for SQL Server Description: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

 

In my MSSQL database I have field(pub_date) of type varchar which stores date in January 1, 2007 format.

In my php page user selects two dates (which are also in the format January 1, 2007) and I have to o/p the records from the database between those two dates.

 

I am writing a query to do that as "SELECT * FROM table WHERE (CAST(pub_date AS DATETIME) BETWEEN '$fromdate' AND '$todate'".

 

Before when I was not using CAST I have not got the expected results when user chooses fromdate= May 1, 2007 and todate  = June 10, 2007, which is may be because my field is a varchar and char J < char M.

 

Now, when I am using CAST...it gives me results but it is also giving me the above error.

 

I would like to know if there is any other way that I can use without getting this error.

 

Thank you all for you help in advance!

Link to comment
https://forums.phpfreaks.com/topic/54591-datetime-conversion/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.