Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

moment date is in range

var new_date = moment().add(3, 'days');
var current_date = moment().format()

var activation_date = moment().add(2, 'days');

console.log(activation_date.isBetween(current_date, new_date))
Comment

moment day in range

//In versions 2.9+ there is an isBetween function, but it's exclusive:

var compareDate = moment("15/02/2013", "DD/MM/YYYY");
var startDate   = moment("12/01/2013", "DD/MM/YYYY");
var endDate     = moment("15/01/2013", "DD/MM/YYYY");

// omitting the optional third parameter, 'units'
compareDate.isBetween(startDate, endDate); //false in this case

/* 
	There is an inclusive workaround ...
	x.isBetween(a, b) || x.isSame(a) || x.isSame(b)
    
    ... which is logically equivalent to
    !(x.isBefore(a) || x.isAfter(b))
*/
//In version 2.13 the isBetween function has a fourth optional parameter, inclusivity.
//Use it like this:
target.isBetween(start, finish, 'days', '()') // default exclusive
target.isBetween(start, finish, 'days', '(]') // right inclusive
target.isBetween(start, finish, 'days', '[)') // left inclusive
target.isBetween(start, finish, 'days', '[]') // all inclusive

// More units to consider: 
// years, months, days, hours, minutes, seconds, milliseconds
// Note: units are still optional. 
// Use null as the third argument to disregard units in which case milliseconds is the default granularity.
// http://momentjs.com/docs/#/query/is-between/
Comment

PREVIOUS NEXT
Code Example
Javascript :: nextjs custom document 
Javascript :: discord js convert timestamp to date 
Javascript :: chartjs stacked bar show total 
Javascript :: javascript dynamicly include another js file 
Javascript :: get all from dir node 
Javascript :: use thymeleaf variable in javascript 
Javascript :: how convert object to string and string to object in javascript 
Javascript :: find element with data attribute jquery 
Javascript :: vue dev server proxy not working 
Javascript :: Append element to a different parent 
Javascript :: electron no menu bar 
Javascript :: express async errors 
Javascript :: vuejs scroll to top 
Javascript :: sum of n numbers in javascript 
Javascript :: string replace javascript 
Javascript :: javascript Find the number of days between two days 
Javascript :: how to numeric value is after point 2 values in javascript 
Javascript :: node get root directory 
Javascript :: get id of first td jquery 
Javascript :: this is a problem related to network connectivity npm 
Javascript :: formdata append react js 
Javascript :: event listener javascript 
Javascript :: react update component after api call 
Javascript :: javascript round date to nearest 15 minutes 
Javascript :: how do i make a link to direct me to a new page when i click on a button in react 
Javascript :: javascript newline in alert 
Javascript :: mongoose custom object schema 
Javascript :: javascript check if number is multiple of 3 
Javascript :: nextjs localstorage 
Javascript :: get last item in array 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =