-1

I have a simple html form that asks for two dates to select, and on the next page they are used in a MySQL query. Problem is, datepicker uses mm/dd/yyyy as the format, and I need yyyy-mm-dd for MySQL.

Is there a simple way to do this? I don't care if the datepicker's format is changed, or if I have to add a middle step to convert it, but whenever I search for examples they all look way overly complicated and include stuff I'm not even using.

I don't think the code is really important since it's so simple, but here's what I have in the header;

<script>
$(function() {
$( "#datepicker" ).datepicker();
$( "#datepicker2" ).datepicker();
});
</script>

And here's what's in the body;

<form method="post" action="stat_report.php">
<h1>Report Summary</h1>
Format: YYYY-MM-DD<br>
Start Date: <input type="text" name="startDate" id = "datepicker"><br>
End Date: <input type="text" name="endDate" id = "datepicker2"><br>
<input type="submit" value="Submit">
</form>

2 Answers2

0

This could solve your Problem: http://api.jqueryui.com/datepicker/#option-dateFormat

Ophidian
  • 607
  • 7
  • 9
0

Like so: $('#someId').datepicker({ dateFormat: 'yy-mm-dd' });

Klemen Tusar
  • 9,261
  • 4
  • 31
  • 28