-2

Can you please help me to get result? New Date = Date + Period

$event.subscribe("data.book", function(data) {
    console.log(data[4].date); //showing result = Thu 15/02/2018
    console.log(data[4].period); // showing result = 3
});

I have done research but not able to find solution because most of the solution showing how to add date but no idea how to gate Day like in this case I want result something like Sun 18/2/2018 where every time date and period value will be dynamic.

Looking for the solution with javascript as this all code is under .js file

Group Of Oceninfo
  • 358
  • 2
  • 3
  • 19
  • 6
    Possible duplicate of [Add days to JavaScript Date](https://stackoverflow.com/questions/563406/add-days-to-javascript-date) – Herohtar Feb 15 '18 at 05:47
  • What do you mean by "period", day / days? – Nitin Dhomse Feb 15 '18 at 05:50
  • 1
    a day has 86,400,000 milliseconds – Jaromanda X Feb 15 '18 at 05:54
  • @NitinDhomse : period = how many days – Group Of Oceninfo Feb 16 '18 at 01:14
  • @Herohtar: I have seen that post while looking for the solution but it's for the current date and in this case I am getting any random date whatever is enter by user using data[4].date field is providing date (Thu 15/02/2018) whatever user has selected. – Group Of Oceninfo Feb 16 '18 at 01:16
  • @GroupOfOceninfo Take a look through the answers and read the [documentation for Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date). Just because the question asks about current date doesn't mean the same principle can't be used for other dates. If you need more advanced date manipulation, take a look at [moment](https://momentjs.com/). – Herohtar Feb 16 '18 at 05:02

1 Answers1

1
var result = “Thu 15/02/2018”;
var date = result.split(' ')[1];
date = date.replace(/\//g , ‘-‘);
var cdate= new Date(date.replace( /(\d{2})-(\d{2})-(\d{4})/, 
"$2/$1/$3"));
date = new Date(cdate.setDate(cdate.getDate() + 3)); 
d.getDate() + '/' + d.getMonth() +'/'+ d.getFullYear(); // 18/02/2018
Bhoomi Bhalani
  • 295
  • 5
  • 19