hungryOrb Posted October 4, 2007 Share Posted October 4, 2007 Hallo, trying to put a PHP Date() into my MySQL db DATETIME column, but ehh.. its saying: Error: Incorrect datetime value: '' for column 'Started' at row 1 This makes me sad, is anyone knowing exactly what format I should use to store PHP's date function in my database properly? I nub. Sari Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted October 4, 2007 Share Posted October 4, 2007 date in mysql is YYYY-MM-DD if you use date time its YYYY-MM-DD HH:MM:SS make sure your php dates reflect that - date('Y-m-d') or date('Y-m-d H:i:s'); Quote Link to comment Share on other sites More sharing options...
hungryOrb Posted October 4, 2007 Author Share Posted October 4, 2007 Thankyou very much for showing me the format! however, it is stil giving the same message, must I put something between date('Y-m-d H:i:s'); the date, and time? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted October 4, 2007 Share Posted October 4, 2007 well if you are not using the current date and time you need to use date('Y-m-d H:i:s', mktime(#timestamp of your date/time#)) Quote Link to comment Share on other sites More sharing options...
hungryOrb Posted October 4, 2007 Author Share Posted October 4, 2007 Yes, using the current server time. As follows: $started_query = mysql_query("SELECT Started FROM jobs WHERE `ID`='".$_POST["id"]."'"); IF (($_POST['started'] == "chk") && ($started_query == "")) { $started_store = date('Y-m-d H:i:s'); } $sql="UPDATE jobs SET `Started`='".$started_store."' WHERE `ID`='".$_POST["id"]."'"; Just want to put it straight into a var, then directly into the database.. :'( ty for help though ;] Quote Link to comment Share on other sites More sharing options...
madspof Posted October 4, 2007 Share Posted October 4, 2007 I dont know what field type you are using to store the date and time but i use varchar and it works fine also make sure the field is set, so that it allows enought characters for the date Quote Link to comment Share on other sites More sharing options...
hungryOrb Posted October 4, 2007 Author Share Posted October 4, 2007 hm, thanks. Not sure If I wanna give up on my DATETIME field type atm! BUT-! hmm, what do you mean by the field being seT? You mean throw some generic values in the appropriate format in there to simply replace with UPDATE? If so, then my IF statement becomes worthless Quote Link to comment Share on other sites More sharing options...
madspof Posted October 4, 2007 Share Posted October 4, 2007 I mean so that the field can acept how long the date and time recorded is like if it is 10 characters and the field is set to only 5 it will not acept all the characters Quote Link to comment Share on other sites More sharing options...
hungryOrb Posted October 4, 2007 Author Share Posted October 4, 2007 Oh I see, please could you tell me how to do this? ;]]]] Quote Link to comment Share on other sites More sharing options...
madspof Posted October 4, 2007 Share Posted October 4, 2007 Okay well what database are you using Quote Link to comment Share on other sites More sharing options...
hungryOrb Posted October 4, 2007 Author Share Posted October 4, 2007 MySQL and the database name is ITDB. Quote Link to comment Share on other sites More sharing options...
madspof Posted October 4, 2007 Share Posted October 4, 2007 I guess you have somekind of program like phpadmin to access the db Quote Link to comment Share on other sites More sharing options...
hungryOrb Posted October 4, 2007 Author Share Posted October 4, 2007 ehm, just changing the field types and stuff in MySQL Query Browser Quote Link to comment Share on other sites More sharing options...
hungryOrb Posted October 4, 2007 Author Share Posted October 4, 2007 Arg! Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted October 5, 2007 Share Posted October 5, 2007 if you are just inserting the current time use NOW() in teh mysql query and don't bother with any of teh php date stuff - its unnessesscary! Quote Link to comment Share on other sites More sharing options...
hungryOrb Posted October 5, 2007 Author Share Posted October 5, 2007 Thanks guys, got it solved with all of your help and some messing with stuff ;] Quote Link to comment 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.