0

the user provide value is var date = 2019/11/06 22:59:50; but i want to convert the data of date as date = 55; from ("YYYY/MM/DD HH:mm:ss") to ("mm") having only the minute so that i can subtract the data as alert(date - Date().getMinute()) so that i can save the value to a variable for conditions

2 Answers2

1

Date manipulation is really rough in JS. If you can ensure the format is going to be exactly like that, you can do something like this:

var date_raw = "2019/11/06 22:59:50";
var date = new Date(date_raw);
var mm = date.getMinutes();

Otherwise, I suggest you look into moment.js if you need something more complex.

Edit: if you're just looking for help on subtracting time from a date object, that's already answered

Andrew
  • 763
  • 7
  • 21
0

If I understand what you want, in first place I would transform the date var into a Date object, like this: var date = new Date("2019/11/06 22:59:50");. Then I'd add a min var that would take the mm part of the date like this: var min = date.getMinutes();. That would do the job.

JDE10
  • 556
  • 1
  • 3
  • 13