-1

I have a date:

start : 2022-07-13 08:22:22
process : 50 minute

And I want to output sum total

total = 2022-07-13 09:12:22 // total = start + process minute

I'm using javascript for sum

function myFunction() {
  var datestart = $("#start").val();
  var process = $("#process").val();
  total = datestart + process;
  alert(total);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
mplungjan
  • 169,008
  • 28
  • 173
  • 236
Nest
  • 13
  • 4
  • 1
    Please visit the [help], take the [tour] to see what and [ask]. Do some research - [search SO for answers](https://www.google.com/search?q=javascript+add+minutes+to+date+site%3Astackoverflow.com). If you get stuck, post a [mcve] of your attempt, noting input and expected output using the [\[<>\]](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do) snippet editor. – mplungjan Jul 13 '22 at 06:59

1 Answers1

0

const dateStr = '2022-07-13 08:22:22';
const date = new Date(dateStr);

const addMinutes = (d, minutes) => {
  const _date = new Date(d);
  _date.setMinutes(_date.getMinutes() + minutes);
  return _date;
}

const format = (date) => {
  return date.toISOString().replace("T"," ").substring(0, 19);
}

console.log('original time', format(date));
console.log('add 30 minutes to the original time', format(addMinutes(date, 30)));
console.log('add 50 minutes to the original time', format(addMinutes(date, 50)));
Ian
  • 1,198
  • 1
  • 5
  • 15