insert date value into sql using php?
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
Code:
$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
Re: insert date value into sql using php?
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.
Re: insert date value into sql using php?
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.
Re: insert date value into sql using php?
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?
Re: insert date value into sql using php?
hi how to bind the post value of date using php for sql
can u give sample code ..
Code:
$now=date("Y/M/D H:I:S");
but it produce like this Jul 5 1905 12:00AM
Re: insert date value into sql using php?
Please start trying to do some of your own work...http://ar2.php.net/manual/en/function.date.php
Re: insert date value into sql using php?
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.
Code:
$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
Re: insert date value into sql using php?
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.