Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7897453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:10:12+00:00 2026-06-03T08:10:12+00:00

I’ve had quite a few clients complain about when they change the date on

  • 0

I’ve had quite a few clients complain about when they change the date on the JQuery Datepicker, it doesn’t update the date… This is because they change the month/year and expect it to update the date without selecting one.

So I thought I’d help them out and update the date for them automatically using the onChangeMonthYear() function.

My code is below. When I change the month or year, it takes me to 2017 or 1987… I don’t understand what is wrong. Am I missing something?

$('#member_birthday_full').datepicker({ 
    altField: '#member_birthday',
    altFormat: 'yy-mm-dd',
    changeMonth: true,
    changeYear: true,
    dateFormat: 'DD, d MM yy',
    showAnim: 'slideDown',
    yearRange: '-125:+0',
    onChangeMonthYear:function(y, m, i){                                
        var d = i.selectedDay + '';                       
        if (d.length < 2) 
            d = '0' + d;                       
        var m = m + '';                       
        if (m.length < 2) 
            m = '0' + m;   
        $(this).datepicker( "setDate", y + '-' + m + '-' + d ); 
    }
});​

http://jsfiddle.net/3YQZV/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:10:14+00:00Added an answer on June 3, 2026 at 8:10 am

    The easiest solution (see demo) is to set the new date using a Date object:

    onChangeMonthYear:function(y, m, i){                                
        var d = i.selectedDay;
        $(this).datepicker('setDate', new Date(y, m - 1, d));
    }
    

    From the fine manual:

    setDate(date)
    […]
    date
    Type: String or Date
    The new date.

    But you’re setting the new date in the altFormat. Then the datepicker tries its best to parse the yy-mm-dd date using the DD, d MM yy format and you end up in 1887 all dazed and confused and wondering where your DeLorean is.

    You’ll also want to decide what you’re going to do if they try to move from, say, January 31 to February. You’d probably want to go to February 28 (or 29 in a leap year). Similar issues will come up if you start at January 29, January 30, May 31, … and go forward one month; slightly different issues arise if you start at June 30 and try to go back one month. I’ll leave that as an exercise for the reader.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.