Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

momeny 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 :: read csv file in javascript 
Javascript :: encode in javascript 
Javascript :: join two arrays angular 
Javascript :: react native flatlist 
Javascript :: new date() in javascript 3 days from now 
Javascript :: vue.js cdn script 
Javascript :: how to show bootstrap 5 modal using jquery 
Javascript :: react hook toggle state 
Javascript :: how to import background image in inline css in react 
Javascript :: javascript confirm tab close 
Javascript :: Javascript find element with focus 
Javascript :: update nodejs ubuntu 
Javascript :: javascript on image load 
Javascript :: jquery image change on hover 
Javascript :: jQuery CSS Classes 
Javascript :: audio in react 
Javascript :: jquery selector checked 
Javascript :: lodash filter object keys 
Javascript :: javascript rtsp player 
Javascript :: debug react vscode 
Javascript :: isarray 
Javascript :: get size of json object 
Javascript :: react materilize 
Javascript :: sass config.json vs code 
Javascript :: multidimensional array push in jquery 
Javascript :: get element by id in javascript 
Javascript :: node.js for windows 7 
Javascript :: express trust proxy 
Javascript :: redux persist a non-serializable value was detected in an action in the path register 
Javascript :: add tailwind to create react app 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =