I am writing a page that will accept some info from user and get submitted as form. I wanted the date included in the form data so I wrote this little snippet to insert the current date when form is submitted:
<li>
<input type="hidden" id="date" name="Date_val" value="date">
<script type="text/javascript">
document.getElementById('date').value = Date();
</script>
</li>
Now when I print out my form all I get is a nonsense date 11--00-01 printed in my table. Looking at the _POST info this is what is getting sent to MySQL:
Array ( [formID] => 42796558181164 [Date_val] => Wed Oct 22 2014 17:50:43 GMT-0400 (Eastern Standard Time) etc...
I'm assuming that is why I get gibberish as my output. I have the MySql object defined as a simple date format. Can anyone tell me how I should format the date so MySQL will accept it and will output correctly?
Thanks...
Answer:
<li>
<input type="hidden" id="date" name="Date_val" value="date">
<script src="jscripts/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
date_tda = new Date().toISOString().slice(0, 19).replace('T', ' ');
document.getElementById('date').value = date_tda;
</script>
</li>