3

I am using the Jquery date picker to select a date. When I select a date the format of the date in the textbox is mm-dd-yyyy and I would like dd-mm-yyyy.

Textbox

Date: <input type="text" id="datepicker"/>

JQuery

$(function() {
$( "#datepicker" ).datepicker({ dateFormat: "dd/mm/yy"});
});

If I then adapt the text box by including a default date:

<input type="text" value="<?php echo date("d/m/Y"); ?>" id="datepicker" />

The default date appears as I would like in the input box ie dd/mm/yy, but when I open the date picker it takes this date as mm/dd/yy and therefore opens the date picker on the wrong date.

The text box and the picker do not seem to thinking in the same format. How do I correct this?

UPDATE

The issue is now:

1 - when I open the page the default date in textbox is correct and in the right format dd/mm/yy

2 - when I open the date picker the date picker goes to the correct date ie the default date

3 - when I then choose a date from the date picker the format reverts to mm/dd/yy in the text box

Does, when using JQuery to update an id, the format of the text box get bypassed in some way?

5
  • constrainInput: true Commented Sep 25, 2013 at 7:36
  • I can't replicate that, perhaps you could put together a minimal, self-contained example demonstrating the problem and post it to jsbin.com or http:/jsfiddle.net. Edit: Ah, but I was using type="text", as in your HTML snippet. Commented Sep 25, 2013 at 7:37
  • Some browsers are rendering the type="date" if supported. This is screwing up the jQueryUI datepicker initialization I think. Commented Sep 25, 2013 at 7:42
  • @ Richard: You first snippet uses type="text", your second uses type="date". Please edit the question to make them consistent, reflecting what you're actually using. Commented Sep 25, 2013 at 7:42
  • I appreciate all the comments and help. The type="text" or type="date" does not appear to make any difference at all. Commented Sep 25, 2013 at 8:03

2 Answers 2

2

You've actually changed the type attribute of your input box to a date. Keep it as text and it should be fine:

<input type="text" value="<?php echo date("d/m/Y"); ?>" id="datepicker" />
Sign up to request clarification or add additional context in comments.

Comments

-1

Here's one specific for your code:

var date = $('#datepicker').datepicker("option", "dateFormat", "dd/mm/yy");

More general info available here:

http://api.jqueryui.com/datepicker/#option

http://api.jqueryui.com/datepicker/#utility-formatDate

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.