Copy link to clipboard
Copied
i have used a jquery datepicker http://jqueryui.com/datepicker/
i have a databse with the following feild
Field | Type | Null | Default
---------------------------------------
date | date | No | 0000-00-00
i have a page with the jqury date picker
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
and the following php and form feild
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO CalendarBetty (`date`) VALUES (%s)",
GetSQLValueString($_POST['date'], "date"));
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<input type="text" name="date" value="" id="datepicker" size="32" />
<input type="hidden" name="MM_insert" value="form1" />
when i add a date using the picker that is attached to the text feild it is storing the default value of 0000-00-00
Here is the script I use to force the right formatting. You should be able to modify it for your use:
<script>
$.datepicker.setDefaults({
showOn: 'focus',
buttonText: '' });
$("#date1").datepicker({dateFormat: 'yy-mm-dd'});
</script>
An alternative would be to use PHP to change the format before updating the database.
Copy link to clipboard
Copied
looks like its the way the date is formatted. the jqury uses
00/00/0000
the database uses
0000-00-00
i need to get the jquery to change to the same as the DB
Copy link to clipboard
Copied
Here is the script I use to force the right formatting. You should be able to modify it for your use:
<script>
$.datepicker.setDefaults({
showOn: 'focus',
buttonText: '' });
$("#date1").datepicker({dateFormat: 'yy-mm-dd'});
</script>
An alternative would be to use PHP to change the format before updating the database.
Copy link to clipboard
Copied
thanks, i tried
$.datepicker.setDefaults({
showOn: 'focus',
buttonText: '' });
$("#date1").datepicker({dateFormat: 'yy-mm-dd'});
<input type="text" name="date" value="" id="date1" size="32" />
but that didnt display the date pciker
Copy link to clipboard
Copied
this done it
<script type="text/javascript">
$(function() {
$("#datepicker").datepicker({ dateFormat: "yy-mm-dd" }).val()
});
</script>
Copy link to clipboard
Copied
That's right. You need to use your own variable ID. Sorry I didn't clarify that.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more