Check date is expired or not on Moment Date format

moment check if date is after another
moment format
moment#isbefore
moment is valid
moment#issame
moment to date
check if date is today momentjs
momentjs is date in future

I have a date Format like this

[{"Exp_Date":"28-Feb-19"},{"Exp_Date":"30-Apr-19"},{"Exp_Date":"28-Jun-19"},{"Exp_Date":"29-Nov-19"}]

Now I have to check whether my Date is less that First value of array of objects. If less then I have to pick First object,

If that date expired then I have to use the next date.

I want to implement this on Moment.

I know the subtract of moment but that not solve my purpose. Anyone can guide me how to solve this. Any help is really appreciated


You could do this check in a loop:

var array = [{"exp_date":"28-Feb-19"},{"exp_date":"10-Feb-19"}];
for(i=0;i<array.length;i++){
    console.log(moment(new Date()).isAfter(moment(new Date(array[i]["exp_date"]))));
}

This uses new Date() objects which seem to be easier on moment

Is Before, isBefore(Moment|String|Number|Date|Array, String);. Check if a moment is before another moment. The first argument will be parsed as a moment, if not already so � A time zone is crucial in determining a date. For any given moment, the date varies around the globe by zone. For example, a few minutes after midnight in Paris France is a new day while still “yesterday” in Montréal Québec. If no time zone is specified, the JVM implicitly applies its current default time zone.


const a = [{ "Exp_Date": "28-Feb-19" }, { "Exp_Date": "30-Apr-19" }, { "Exp_Date": "28-Jun-19" }, { "Exp_Date": "29-Nov-19" }];
let i = 0;
while (a[i] && moment().isAfter(moment(a[i].Exp_Date),'DD-MMM-YY')) { // <-- change this
    i++;
}
if (a[i]) {
    return a[i];
} else {
    return null;
}

updated answer of Nguyen

Is After, isAfter(Moment|String|Number|Date|Array, String);. Check if a moment is after another moment. The first argument will be parsed as a moment, if not already so. Supposing the current date is 2015/5/25, with the following formula, you can determine if date has passed compared with today’s date. Please do as follows. 1. Select a blank cell which is adjacent to the date you want to determine if it is overdue. Enter the below formula into it, and then press the Enter key.


Try this

const a = [{ "Exp_Date": "28-Feb-19" }, { "Exp_Date": "30-Apr-19" }, { "Exp_Date": "28-Jun-19" }, { "Exp_Date": "29-Nov-19" }];
let i = 0;
while (a[i] && moment().isAfter(moment(a[i].Exp_Date, "DD-MMM-YY"))) {
    i++;
}
if (a[i]) {
    return a[i];
} else {
    return null;
}

You can see it here

Date Validation Using Moment.js, Since the HTML5 date type is still not widely supported by browsers, many Learn how to use Moment.js's constructor and date validation methods to In short, it checks if the string matches known ISO 8601 formats or RFC� To make the answer more re-usable for things other than just the datepicker change function you can create a prototype to handle this for you.


Well i dont know about moment but this could easily be done will js.

var dates =[{"Exp_Date":"28-Feb-19"},{"Exp_Date":"30-Apr-19"},{"Exp_Date":"28-Jun-19"},{"Exp_Date":"29-Nov-19"}]

var d = new Date("01-march-19");
// sort the array first, this is optional, then find the current Exp_Date Index
var index = dates
 .sort((a,b)=> new Date(a.Exp_Date) - new Date(b.Exp_Date))
 .findIndex((item)=> new Date(item.Exp_Date) >= d);
 
console.log(dates[index])

moment js display date Code Example, Get code examples like "moment js display date" instantly right from your moment().format(); // "2019-08-12T17:52:17-05:00" (ISO 8601, no fractional isArray Because arrays are not true array in JavaScript, there is no simple typeof check. value in textbox using jquery � how to set expire time of jwt token in node js� Now to auto fix the date’s, double click on the right border of the column to resize it. Or else, to set the column width; just drag it to the right border to fix the date format Excel not working issue. So, this method is applicable for date format not changing in Excel 2007, 2013, 2016. Method #4: Change The Date To Number Format


Moment.js documentation — DevDocs, To get the current date and time, just call moment() with no parameters. we then check if the string matches the RFC 2822 Date time format before dropping to� Highlight expired or upcoming date with Conditional Formatting. To apply Conditional Formatting to highlight the expired or upcoming dates, please follow these steps: 1. Select the due date cells, and then click Home > Conditional Formatting > New Rule. See screenshot: 2.


Guides, Check out this scrimba moment guide if you're just starting. Date math does not use a linear time scale, but rather increments or decrements the //date math moment('2016-03-12 13:00:00').add(1, 'day').format('LLL') "March 13, 2016 1:00� Today (12 June 2012) is 41072 or that many days since 1 jan 1900. we can ceck if the cell is formatted as a date but that doesn't mean it contains one or we can check if it's a number =isnumber(p1) But we can't specifically test if it's a date without resorting to VB code. The code below in a general module will test for a date. call with


Form Validation: Date and Time < JavaScript, I'm not going to show that here, but you can find a link to When you enter a date in the format dd/mm/yyyy the value is sent via an Ajax call to the server where it is validated using the PHP checkdate function. form, AjaxRequestXML.js, ajaxresponsexml.php and� If the expiration date remains unchanged after 48 hours from your renewal purchase Make sure you have an Internet connection. Verify that your computer can access the Internet. Verify that your connection is not intermittent or timing out. Check the serial number of your Trend Micro Security: