1

I have a date taken as a url parameter and I need to use that date to set another date in a another field. What I need to do exactly is take the url parameter, add 1 month and 2 weeks to it, display the new date in a text field. I am doing this in a jsp page.

my url parameter:- 13-10-2014 new field :-

<input type="text" id="newDate" value="">

I followed this thread, but I cannot figure out how to do it with a String value(The url parameter).

How to do this. Thank you!

Community
  • 1
  • 1
vigamage
  • 1,975
  • 7
  • 48
  • 74
  • your question is not clear but you may give a try to this inside your datepicker code : dateobj = $.datepicker.parseDate('mm-dd-yy', string_from_url); – Adesh Pandey Oct 13 '14 at 12:23

2 Answers2

1

I can't understant what you really want any way try this, this may help you,

suppose your url is something like this http://test.test.php?fromdate=13-10-2014 then access fromdate as a get URL parameter.

var initialDate = "13-10-2014";
var dateArray = initialDate.split("-");
var dateObj = new Date(dateArray[2],parseInt(dateArray[1]-1),dateArray[0]);
dateObj.setMonth(dateObj.getMonth()+1);
dateObj.setDate(dateObj.getDate()+14);
alert(dateObj);
alert(dateObj.getDate()+"-"+parseInt(dateObj.getMonth()+1)+"-"+dateObj.getFullYear());

actually you have to consider browser locale before set final date string. i.e date should be formatted as browser locale otherwise date picker plugin may not work

  • the second alert gives me the date as 15-0-2015. it should be 15-01-2015 – vigamage Oct 13 '14 at 15:00
  • Oh sry for the small mistake. I edited the answer. javascript date object accept month as the second argument which should be zero basis. i.e. 0 for January ... 11 for December. So I decremented 1 when creating the object and added 1 when displaying the date. – Nishan Senevirathna Oct 14 '14 at 03:10
-2

You can try this for Date picker.

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>jQuery UI Datepicker - Default functionality</title>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css">
    <script>
      $(function() {
        $( "#newDate" ).datepicker();
      });
    </script>
  </head>
  <body>
    <p>Date: <input type="text" id="newDate" value=""></p>
  </body>
</html>