Click to See Complete Forum and Search --> : PHP insert date value into sql using php?


goldenswarna
January 31st, 2011, 12:20 AM
i want to store date in many fields of sql server 2000, the date field having the datatype datetime and i pass the value to the date field like below

$now=date("m/d/Y h:i:s A");

mssql_bind($stmt,"@s_date", $var1,SQLINT4);



first variable got insert the now date successfully but other dates values didnt insert now value it store like 1/2/1900 12:00:00 AM


why it behave like this can any one suggest me answer to this


thanks
sona

PeejAvery
January 31st, 2011, 08:04 AM
Date formatting for SQL and SQL derivatives is "YYYY/MM/DD HH:MM:SS" and not as you have it. Note that the hour is 24, not 12.

goldenswarna
January 31st, 2011, 11:37 PM
hi thanks for ur reply

i want this format to be stored in database "m/d/Y h:i:s A" ?

how to i achieve this using php and store it in database.

PeejAvery
February 1st, 2011, 07:37 AM
The only way to do that is to make the column of varchar type. But, that's a very, very poor implementation because then you lose the date/time object.

Use the proper format and just display the formatted date with PHP. Why do you think that PHP has such an extensive date/time function set?

goldenswarna
February 2nd, 2011, 04:18 AM
hi how to bind the post value of date using php for sql

can u give sample code ..


$now=date("Y/M/D H:I:S");



but it produce like this Jul 5 1905 12:00AM

PeejAvery
February 2nd, 2011, 04:55 AM
Please start trying to do some of your own work...http://ar2.php.net/manual/en/function.date.php

goldenswarna
February 2nd, 2011, 10:50 PM
hi

what is datatype for bind the datetime into msssql. i used sqlint4 but it is not correctly bind value.

i know about the date functions.


$now="1/2/2003";

mssql_bind($stmt,"@s_date", $now,SQLINT4);


@s_date datetime

i bind now variable to datefield but in database didnt store this value instead of it store the default time

1/2/1900 12:00:00 AM

the problem is the datatype i passed or data value which is i used ? can u guide me

PeejAvery
February 3rd, 2011, 04:47 PM
That's because binding requires that the variable be of the same time. Since PHP does not have a datetime type variable, you need to use a query, not a bind.