Avatar of tjyoung
tjyoung

asked on 

change dateformat when using to/from jquery datepicker?

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
JavaScript

Avatar of undefined
Last Comment
tjyoung
ASKER CERTIFIED SOLUTION
Avatar of strickdd
strickdd
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of tjyoung
tjyoung

ASKER

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
Avatar of tjyoung
tjyoung

ASKER

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
Avatar of tjyoung
tjyoung

ASKER

Hi,
Had a freaking typo before. Worked once I caught that.
Thanks
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo