I'm using a DatePicker to let someone pick a certain week.
The html is basically like this:
<form method="post" action="">
<input type="text" id="beginDate" />
<input type="text" id="endDate" />
</form>
And the javascript is this now:
<script type="text/javascript">
$(function () {
$("#beginDate").datepicker(
{ dateFormat: "dd-mm-yy",
onSelect: function () {
var mon = $(this).datepicker('getDate');
mon.setDate(mon.getDate() + 1 - (mon.getDay() || 7));
var sun = new Date(mon.getTime());
sun.setDate(sun.getDate() + 6);
$(this).val(mon);
$('#endDate').val(sun);
}
});
});
</script>
That works, kind of... It puts Mon Nov 21 2011 00:00:00 GMT+0100 and Sun Nov 27 2011 00:00:00 GMT+0100 in my textboxes.
I want them to be in a "dd-mm-yyyy" format, so just 21/11/2011.
I tried things such as .formatDate, but that does not seem to work.
I know I could do something like mon.GetDay() + "/" + mon.GetMonth() + "/" etc but javascript must have some kind of proper date formatter, right?
There is no date format function in JavaScript itself, but you are using jQuery ui so try this:
$('#endDate').val($.datepicker.formatDate('dd/mm/yy', sun));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With