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 8752565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:15:40+00:00 2026-06-13T13:15:40+00:00

So, I have this code : $(‘#end_date’).click(function() { var start_date = new Date($(‘#start_date’).val()); var

  • 0

So, I have this code :

$('#end_date').click(function() 
{
    var start_date = new Date($('#start_date').val());
    var duration = parseInt($('#duration').val());

    var end_date = new Date();
    end_date.setDate(start_date + duration);

    $('#end_date').val($.datepicker.formatDate('yy-mm-dd', end_date));
});

Which, I believe, should take a start date from the form, and add some days (duration) in it, and the show the output in the other text field. However, the result I got is always NaN-NaN-NaN, or simply Invalid Date if I remove the formatting.

However :

$('#end_date').val($.datepicker.formatDate('yy-mm-dd', start_date));

works just fine. So I don’t think the problem lies in the 3rd line. And now I confused. Any pointer to solve this problem?

  • 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-13T13:15:41+00:00Added an answer on June 13, 2026 at 1:15 pm

    setDate just sets the day of the month, and you could use setFullYear and setMonth or you can do this.

    $('#end_date').click(function() 
    {
        var start_date = new Date($('#start_date').val());
        var duration = parseInt($('#duration').val());
    
        var end_date = new Date();
        end_date.setDate(start_date.getMilliseconds() + duration.getMilliseconds());
    
        $('#end_date').val($.datepicker.formatDate('yy-mm-dd', end_date));
    });
    

    Hoping that start_Date and duration are returning milliseconds.

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

Sidebar

Related Questions

I have this code <script type=text/javascript> $(function () { $(.a).live(click, function () { var
I have this code to load the content from another file $(document).ready(function(){ $(button).click(function(){ $(#divA).load(book.html
i have this code: function MyClient() { var personPath = M255.968,166.154c34.206,0,61.936-27.727,61.936-61.934c0-34.208-27.729-61.936-61.936-61.936s-61.936,27.728-61.936,61.936 C194.032,138.428,221.762,166.154,255.968,166.154z M339.435,194.188c-13.082-13.088-28.625-20.924-84.83-20.924 c-56.214,0-71.38,8.505-83.796,20.924c-12.422,12.416-8.23,144.883-8.23,144.883l27.485-65.304l17.28,194.554l49.856-99.57
I have this code var contacts = dr.mktDoctorContacts .GroupBy(x => x.ContactType) .Select(zb => new
I have this code : void Main() { System.Timers.Timer t = new System.Timers.Timer (1000);
I have this code: con.Open(); cmd = new MySqlCommand(String.Format(SELECT concat(name,'|',lastname) FROM {0} WHERE ID=
I have this code: class LFSeq: # lazy infinite sequence with new elements from
I have this code: Locale locale_en = new Locale(en); Locale.setDefault(locale_en); Configuration config_en = new
I have this code: function boo() { this.is_global = Yes!; } When I run
I have this code: var mods1 = ['a', 'b', 'c', 'd']; var mods2 =

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.