# Category: momentjs

## Javascript – Calculate number of days between two weekdays

I looking for a function that calculate the day difference between two weekdays. Like, for eg. Monday – Friday = 4 Sunday – Saturday = 6 Thank you! Source: AngularJS

## How i get days accurately in Moment.js

This is my code for getting days difference from given dates. I need the days accurately, Here my correct days different is ‘2’ but i am getting 1. i am using moment.js for this operation in angular. This is not taking time . I need time to take for getting result. I am using this code in calendar so i need to take time too. var startdate=new Date(‘2017-12-30 06:00:00’); var enddate=new Date(‘2018-01-01 01:00:00’); var diff= […]

## why moment().get(‘month’) are zero indexed?

I recently started using moment() . According to this documentation , it says moment().get(‘month’); are zero indexed. Means January is indexed 0 till December is indexed 11. Any particular reason for that ? Regards Source: AngularJS

## Do I need momentJS if I’m using moment-with-locales?

Right now I’m adding scripts in my project in following sequence: window.top.ak.getScript([ window.top.akContextPath + “/scripts/css/xxx.css”, window.top.akContextPath + “/scripts/js/xxx.min.js”, window.top.akContextPath + “/scripts/js/polyfills.min.js”, window.top.akContextPath + “/scripts/js/jquery.min.js”, currHost + “/components/lib/lodash.min.js”, window.top.akContextPath + “/scripts/js/moment.min.js”, window.top.akContextPath + “/scripts/js/angular.min.js” ], function() { window.top.ak.getScript([ window.top.akContextPath + “/scripts/js/angular-messages.js”, window.top.akContextPath + “/scripts/js/angular-ui-router.js”, window.top.akContextPath + “/scripts/js/angular-animate.js”, currHost + “/components/lib/toaster.min.js”, window.top.akContextPath + “/scripts/js/ui-grid.min.js”, currHost + “/components/lib/defiant.min.js”, window.top.akContextPath + “/scripts/js/xxx-ui.js”, currHost + “/components/lib/polyfill-resize.js”, currHost + “/components/lib/draggable-rows.js”, currHost + “/components/lib/moment-with-locales.js”, ], function() { window.top.ak.getAsset([ currHost + “/components/common.bundle.js”, currHost […]

## Display dates from array in a table

I have a problem where i want create an array of dates using moment.js and then display the contents of the array of dates in a table. <table border=”1″> <tr ng-repeat=”days in arr track by $index”> <td ng-repeat=”d in days track by$index”> {{d}} </td> </tr> </table> Dates are created using moment and pushed to an array var date = moment(), begin = moment(date).startOf(‘week’).isoWeekday(1); var arr = []; for (var i=0; i<35; i++) { arr.push(begin.format(‘D’)); […]

## Optimize the JS Function to filter the data based on Month

Currently, I have written below function to filter the items based on the month and return in Array and I have used below login. Can someone help is there any way I can filter even more easily using datejs or moment js using for loop in more efficient way Here I am getting date in the format of 2/Jan/17 and filtering based on includes method Thanks in advance!! Javascript function getMonthlyCount() { return yearlyExecution() .then(function(myitems) […]

## Exclude weekend dates from working days in JavaScript

So I am kinda stuck in figuring out a certain aspect. What I want to do is the following: Let’s say I just have a simple date display, which will show a date such as October 10th, 2017 to an end user. And then there is an option to subtract a certain number of days from said date (an offset of 1, 2, 3, whatever offset is chosen). What I am looking to do is […]

## momentjs format time in seperate hours an minutes

I use momentjs inside angular js and I acount the duration in seconds and I can format it in HH:mm format as 03:35 but I cannot find in documentaion and google to how show it in format 3h 35m could anybody point me to right documentation??? Source: AngularJS

## What is the most effective way to copy time (hh, mm) from one datetime to another?

I’m trying to write a calendar with timepicker, so that when you change the date, the time stays the same. Both fields (calendar and time) in html use the same variable (vm.inputDate) and I don’t want to change that. Right now I have this function, that triggers on date change: vm.keepTimeUnchanged = function(changedDateTime, oldDateTime) { var hours = oldDateTime.getHours(); var minutes = oldDateTime.getMinutes(); if (!moment(vm.inputDate).isSame((changedDateTime), ‘day’)) { vm.inputDate = changedDateTime; vm.inputDate.setHours(hours, minutes); } return vm.inputDate; […]

## Angular Moment Date Picker date time inconsistency

I have an angular 1.5 application where i make use of a moment datepicker library from here : angular moment date picker Everything has worked well until recently when we realized that the date pickers rendered dates wrongly across different user pc’s .It appears this may have something to do with how JavaScript handles time zones: In the image below October 1, 2017 is actually a Sunday but the date picker renders it as a […]