change dateformat when using to/from jquery datepicker?

Posted on 2011-10-07
Last Modified: 2012-05-12
I've got a 'To/From' datepicker on my site and I'm trying to get my format into yy-mm-dd instead of what the default example is: yy/mm/dd

This is the code I am using (right of the jquery  demo site)

	$(function() {
		var dates = $( "#from, #to" ).datepicker({
			defaultDate: "+1w",
			changeMonth: true,
			numberOfMonths: 2,
			onSelect: function( selectedDate ) {
				var option = == "from" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" ),
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						selectedDate, instance.settings );
				dates.not( this ).datepicker( "option", option, date );

Open in new window

I can see something about the dateformat but can't figure out how to get it to use the right format?

Thanks as always
Question by:tjyoung
    LVL 28

    Accepted Solution

    JQuery has great documentation on their site:

    Basically, set the dateFormat property of the datepicker to "yy/mm/dd"

    LVL 1

    Author Comment

    yes I saw that. Unfortunately I can't see how to place that into the example code they have for a 'date range picker'.
    The only sample is you choose from a dropdown what format and it shows it appropriately.

    Doesn't show how to set a default format when you initialize it.

    My format I'm after is yy-mm-dd

    The default it uses is yy/mm/dd
    LVL 1

    Author Comment

    I've tried putting this in to format the 'from'
    $( "#from" ).datepicker({ dateFormat: 'yy-mm-dd' });

    doesn't change it from the yy/mm/dd
    LVL 1

    Author Closing Comment

    Had a freaking typo before. Worked once I caught that.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    A common challenge, or question, when working with two calendar dates is: What is the difference between the specified days? As is frequently the case, the answer is: It depends... What kind of difference do you want? Given two date obje…
    This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now