Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.