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 :: inline style in nextjs 
Javascript :: change url with javascript after 5 seconds 
Javascript :: aos js 
Javascript :: bootstrap carousel click event next previous 
Javascript :: javascript string pop 
Javascript :: js enter key event listener 
Javascript :: javascript get date name 
Javascript :: vue watch handler 
Javascript :: create an array of size n in javascript 
Javascript :: check if body has class javascript 
Javascript :: multi-line javascript 
Javascript :: string remove accents 
Javascript :: copywithin javascript 
Javascript :: jquery event element is visible 
Javascript :: filter includes array 
Javascript :: javascript execute string code 
Javascript :: typescript class constructor default values 
Javascript :: js delete all array items 
Javascript :: Error serializing `.list Data` returned from `getStaticProps` 
Javascript :: javascript split string only on first instance of specified character 
Javascript :: javascript last element of an array 
Javascript :: convert array to object in javascript 
Javascript :: jquery modal if clicked outside 
Javascript :: check if number is integer js 
Javascript :: install plotly with react 
Javascript :: es6 create array of multiples 
Javascript :: jquery is check 
Javascript :: set cursor type javascript 
Javascript :: how to find the last object in an array 
Javascript :: remove first and last character javascript 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =