SalokinX Posted January 21, 2008 Share Posted January 21, 2008 Hi everyone. I am trying to make a table that when people edit something from it, it will show the date it was edited. This is my code: Code: ( php ) $date = date("m/d/Y"); mssql_query("INSERT INTO news2 (title, dtime, text1, text2) VALUES ('$title', '$date', '$text1', '$text2')"); The thing is that when I check the table, the time is messed up. It shows 4/11/1900 instead of 01/21/2008. I tried using now() instead of '$date' but I get the following error: Warning: mssql_query() [function.mssql-query]: message: Syntax error converting datetime from character string. (severity 16) in C:\xampp\htdocs\news2.php on line 22 Warning: mssql_query() [function.mssql-query]: Query failed in C:\xampp\htdocs\news2.php on line 22 Also, is there a way I can add the time next to the date into the database? Btw, is there a way I could insert the date into the database like this: 12:50am 31/12/2008 Thank you ~ SalokinX Quote Link to comment https://forums.phpfreaks.com/topic/87067-solved-php-mssql-date-problem/ Share on other sites More sharing options...
revraz Posted January 21, 2008 Share Posted January 21, 2008 Sounds like you are trying to insert into a DATE type field in an incorrect format. Quote Link to comment https://forums.phpfreaks.com/topic/87067-solved-php-mssql-date-problem/#findComment-445271 Share on other sites More sharing options...
SalokinX Posted January 21, 2008 Author Share Posted January 21, 2008 So the problem is with MSSQL not PHP? If so, could you tell me how to fix this? Thank you ~ SalokinX Quote Link to comment https://forums.phpfreaks.com/topic/87067-solved-php-mssql-date-problem/#findComment-445278 Share on other sites More sharing options...
revraz Posted January 21, 2008 Share Posted January 21, 2008 echo $date to see what it looks like. I don't know what MSSQL expects it to be in, you may have to check their site or ask in the MSSQL forums. Quote Link to comment https://forums.phpfreaks.com/topic/87067-solved-php-mssql-date-problem/#findComment-445281 Share on other sites More sharing options...
SalokinX Posted January 21, 2008 Author Share Posted January 21, 2008 I did echo $date and it comes out as expected: 01/21/2008 Quote Link to comment https://forums.phpfreaks.com/topic/87067-solved-php-mssql-date-problem/#findComment-445309 Share on other sites More sharing options...
corbin Posted January 21, 2008 Share Posted January 21, 2008 I think you're looking for GETDATE() instead of NOW(). Quote Link to comment https://forums.phpfreaks.com/topic/87067-solved-php-mssql-date-problem/#findComment-445312 Share on other sites More sharing options...
revraz Posted January 21, 2008 Share Posted January 21, 2008 As expected for you, but what about what MSSQL expects? Example, that would fail if you tried to insert that into a MySQL DATE field, because it wants YYYY-MM-DD. I don't know what a MSSQL Date field expects. I did echo $date and it comes out as expected: 01/21/2008 Quote Link to comment https://forums.phpfreaks.com/topic/87067-solved-php-mssql-date-problem/#findComment-445321 Share on other sites More sharing options...
SalokinX Posted January 21, 2008 Author Share Posted January 21, 2008 I think you're looking for GETDATE() instead of NOW(). I got the same error message using getdate() that I was getting with now(). Quote Link to comment https://forums.phpfreaks.com/topic/87067-solved-php-mssql-date-problem/#findComment-445358 Share on other sites More sharing options...
SalokinX Posted January 22, 2008 Author Share Posted January 22, 2008 I got it to work by putting this longer code: $dia = gmdate(d); $mes = gmdate(m); $ano = gmdate(Y); $minuto = gmdate(i); $date = gmdate(H); $brdate = $date - 2; $brdate2 = $brdate; if($brdate < 0) { $brdate2 = $brdate + 12; $ampm = "PM"; } elseif($brdate == 0) { $brdate2 = $brdate + 12; $ampm = "AM"; } elseif($brdate <= 11) { $ampm = "AM"; } elseif($brdate == 12) { $brdate2 == $brdate; $ampm = "PM"; } elseif($brdate >= 13) { $brdate2 = $brdate - 12; $ampm = "PM"; } if($brdate2 < 10) { $hora = "0$brdate2:$minuto$ampm"; } else { $hora = "$brdate2:$minuto$ampm"; } $adddate = "$hora $dia/$mes/$ano"; Quote Link to comment https://forums.phpfreaks.com/topic/87067-solved-php-mssql-date-problem/#findComment-445834 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.