-
January 31st, 2011, 01:20 AM
#1
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
-
January 31st, 2011, 09:04 AM
#2
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.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
February 1st, 2011, 12:37 AM
#3
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.
-
February 1st, 2011, 08:37 AM
#4
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?
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
February 2nd, 2011, 05:18 AM
#5
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
-
February 2nd, 2011, 05:55 AM
#6
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
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
February 2nd, 2011, 11:50 PM
#7
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
-
February 3rd, 2011, 05:47 PM
#8
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.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|