So I have an peculiar set of data: I would need to reduce this to sets of week data. I would convert dates to start of week to get the week data moment(day).startOf(‘isoWeek’) and then concat the data on similar dates and reduce it to single entry. Ending result would look like: But I am looking f…
Tag: momentjs
Moment.js formatting date field to a day earlier than it should
This is a very small little bug I’m trying to fix in my code. I have a React component with this initial state Which is used in a form like so: I’ve done console.logs to see that the Moment(new Date()).format(‘YYYY-MM-DD’) shows today’s date, as I want, but for some reason when t…
Trying to add 5 years using moment
I am trying to add up to 5 years and each year it adds I am storing it to be displayed later. The output ends up being 2026 for all the outputs. I expecting to be: Answer Try the following: Just re-use the original moment object and modify it each time you want to use it.
Get the Second Highest Date in JavaScript/ES6
I have a problem getting the second highest date in ES6. I’m using moment.js too. Its supposed to be getting the id of 3. Answer You should use custom sort function as: There is no need to use find when you are reverseing the array and getting the index 1 from it. Note: I deliberately change the order o…
moment.js returns invalid Date for moment (String, string)
Wants to compare the timestamp. Tried lots of ways but it is throwing an Invalid Date error. The variables startDate /endDate/testDate returns a same timestamp format in ‘DD.MM.YYYY HH:MM:ss’ i.e. ‘21.12.2021 08:29:00’ Also tried using isBetween() function. But for all the conditions i…
How to convert Moment.js moment to unix timestamp
I see a lot in the Moment.js documentation about getting a Moment from a Unix timestamp. However, I am trying to convert a Moment to a Unix timestamp, and I am not sure how to do that. This is how my moment looks: const myMomentObject = moment(str_time, ‘YYYY-MM-DD’); And I need to convert it to a…
How to filter list of objects that doesn’t match some condition in another list of objects
I have an array of objects of optional working hours of some business (5 min jumps). In addition, I have an array of objects of appointments. I want to filter the optional working hours if there is an existing appointment between those hours. I tried this solution with moment.js library: Current result: Dupli…
invalid date printed
I am using moment from mongorc.js (reference: https://raw.githubusercontent.com/gabrielelana/mongodb-shell-extensions/master/released/mongorc.js) when executed this small snippet its printing “invalid date” But in Java: Prints Sun Nov 30 00:00:00 IST 2 Though may not be correct, I want not “…
How can I subtract 1 month using moment.js?
I want to subtract 1 month from a given date in (DD/MM/YYYY) format, but when I do that using moment.js, it gives me the result as 01/12/2020. How can I resolve this? Basically when I click on the left-arrow, the month should be subtracted by 1 every Answer How can I subtract one month using moment.js? tl,dr;…
how to convert minutes to HH:mm with moment plugin
I have 2 timestamps and i already calculated the time difference in minutes with moment plugin. Now i want to convert the minutes to HH:mm. What i am doing wrong? Answer Since you have not specified what is the error, I’m assuming you are leaving the dependencies required for duration method. The moment…