I am using the moment.js library, in nodejs and javascript and I need in two fields "Start_Date" and "End_Date" that the start_date is always 2 hours before the current date, but on point and the end_date will be one hour before the current but on point.
I give an example:
Fecha_Actual: 2019-02-11T14:36
Fecha_Inicio: 2019-02-11T12:00
Fecha_Fin: 2019-02-11T13:00
At this time I collect the information in such a way:
var fechaInicio = moment().format('YYYY-MM-DDTHH:mm');
I've tried some documentation options of this style as mentioned (changing the day for hour but it doesn't work as I need)
moment().day(-7); // last Sunday (0 - 7)
Any help is good.
Greetings and thank you.
MomentJS has a subtract function that is responsible for subtracting seconds, hours, days, etc.
Now, since you want to set the hours and subtract the minutes - if they exist - you must do something like this
In short, we get the current date and subtract two hours from it, leaving the format provided by momentjs by default, since if you try to subtract the minutes from a date with a different format, it won't work . Finally, once you make the necessary subtractions you can give the
format
one you want to your date.Let us know how it goes for you :)