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
Asked
Active
Viewed 70 times
0

Orish Baidhya
- 33
- 7
-
Can you use a library or would the solution have to be without one? – Coola Nov 06 '19 at 17:43
-
Do you mean `date = 59;`? – TKoL Nov 06 '19 at 17:43
-
yes i mean date = 59 – Orish Baidhya Nov 06 '19 at 17:52
-
ya you can use **library ** as will for the solution – Orish Baidhya Nov 06 '19 at 17:53
-
`.getMinutes()` will give you the minute component only, not the date in minutes - *this is of no use to you for comparison*. eg 18:04 -> 04, 17:59 -> 59 - compare 04 with 59? – freedomn-m Nov 06 '19 at 17:54
-
2Possible duplicate of [How do I subtract minutes from a date in javascript?](https://stackoverflow.com/questions/674721/how-do-i-subtract-minutes-from-a-date-in-javascript) – freedomn-m Nov 06 '19 at 17:55
2 Answers
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
-
-
No problem! Feel free to mark the answer as accepted if that's everything you're looking for. – Andrew Nov 06 '19 at 20:53
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