[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

Passing date from PHP to stored procedure in MSSQL 2000

Hi everybody -

I've reached the extent of my tolerance for google searches, and am in need of some help.

I am passing a datetime variable from PHP to a MSSQL (2000) stored procedure. When passing the date, I am using the datatype varchar, as datetime is apparently not an option in MSSQL. I have tried a slew of 'convert' options, but can not seem to get the varchar back into a datetime format to allow my query to work. I error out with: Syntax error converting datetime from character string. (severity 16).

I've also tried different data types:
When I look at the 'date' MSSQL receives from PHP as VARCHAR, ther result is 'J'.
When I look at the 'date' MSSQL receives from PHP as SQLINT4, ther result is '0'.
When I try to pass the 'date' as text, the stored procedure says text 'cannot be compared or sorted , execpt when using IS NULL or LIKE operator'. This won't work, beacuse I need to have a range within 2 seperate exact dates.
It seems that varchar is my best best, but I'm open to other ideas.

The main goal that I am trying to accomplish is to get a date which has been entered on a webpage (in PHP) to run in a stored procedure in (MSSQL 2000) and create a temporary table based on the date from PHP. Any ideas?

Many thanks!
0
asdsstaff
Asked:
asdsstaff
  • 2
  • 2
1 Solution
 
James MurrellProduct SpecialistCommented:
have you looked at http://www.daniweb.com/forums/thread112159.html it may help
0
 
James MurrellProduct SpecialistCommented:
0
 
ZberteocCommented:
Make sure that the length of the parameter is at least 23, so varchar(23). It seem that using varchar simply it only passes 1 character to MSSQL and that's why only J, from January, June or July. What is the format that the PHP page is passing on, like Month DD, YYYY, etc? Depending on this you need to use the convert function in your stored procedure

http://msdn.microsoft.com/en-us/library/ms187928.aspx

convert is used to interchange a datetime type with a string type back and forth depending on the format  the string is in (in) or we want to be in (out).
0
 
asdsstaffAuthor Commented:
YES!!! Zberteoc - THANK YOU!!! My code is working properly now!
0
 
asdsstaffAuthor Commented:
I needed that little boost to figure it out! Thank you!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now