[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

change dateformat when using to/from jquery datepicker?

Posted on 2011-10-07
4
Medium Priority
?
297 Views
Last Modified: 2012-05-12
Hi,
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)

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

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
0
Comment
Question by:tjyoung
  • 3
4 Comments
 
LVL 28

Accepted Solution

by:
strickdd earned 2000 total points
ID: 36931204
JQuery has great documentation on their site: http://jqueryui.com/demos/datepicker/#option-dateFormat

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

0
 
LVL 1

Author Comment

by:tjyoung
ID: 36931233
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
0
 
LVL 1

Author Comment

by:tjyoung
ID: 36931277
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
0
 
LVL 1

Author Closing Comment

by:tjyoung
ID: 36931286
Hi,
Had a freaking typo before. Worked once I caught that.
Thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…
Suggested Courses

834 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