sql server 2008 - Writing date to SQL from php, date is changed -
i have code in php 5.4 creating record in sql server 2008 r2. php code creates date:
$date = date("y-m-d");
which yeilds:
'2015-06-23'
that date used in query sql server:
$insert = 'insert adattend (adenrollschedid, adenrollid, date, starttime, attend, absent, unittype, status, comment, excused, modflag, userid, dateadded, datelstmod, adclassattendid, type) values ('.$adenrollschedid.','.$adenrollid.','.$date.',\'1899-12-30 07:00:00.000\','.$present.','.$absent.',\'m\',\'a\',\''.$comment.'\',0,\'a\','.$instructorid. ','.$date.','.$date.','.$adclassattendid.',\'a\')';
the query seems work fine. record inserted should be. when check record in table dates are:
'1905-06-23 00:00:00.000'
so question is, why altering 2015 1905?
insert escape quotes or use double quotes in single quotes
$insert = 'insert adattend (adenrollschedid, adenrollid, date, starttime, attend, absent, unittype, status, comment, excused, modflag, userid, dateadded, datelstmod, adclassattendid, type) values ('.$adenrollschedid.','.$adenrollid.',\''.$date.'\',\'1899-12-30 07:00:00.000\','.$present.','.$absent.',\'m\',\'a\',\''.$comment.'\',0,\'a\','.$instructorid. ','.$date.','.$date.','.$adclassattendid.',\'a\')';
or
$insert = 'insert adattend (adenrollschedid, adenrollid, date, starttime, attend, absent, unittype, status, comment, excused, modflag, userid, dateadded, datelstmod, adclassattendid, type) values ('.$adenrollschedid.','.$adenrollid.',"'.$date.'",\'1899-12-30 07:00:00.000\','.$present.','.$absent.',\'m\',\'a\',\''.$comment.'\',0,\'a\','.$instructorid. ','.$date.','.$date.','.$adclassattendid.',\'a\')';
Comments
Post a Comment