Is it possible with e regular Expression to do the following
30 days after from the end of current month
example 06-May-2020, Payment date should calculate as 31-May-2020 + 30 days i.e. 30-June-2020
Thanks in advance
Is it possible with e regular Expression to do the following
30 days after from the end of current month
example 06-May-2020, Payment date should calculate as 31-May-2020 + 30 days i.e. 30-June-2020
Thanks in advance
According to FCC This is what Regex exp are:
Regular expressions are special strings that represent a search pattern. Also known as “regex” or “regexp”, they help programmers match, search, and replace text. Regular expressions can appear cryptic because a few characters have special meaning. The goal is to combine the symbols and text into a pattern that matches what you want, but only what you want. This section will cover the characters, a few shortcuts, and the common uses for writing regular expressions.
That is what they do. I think u can answer ure own question now
Depending on the context of the problem, you might use a regular expression in that scenario, but the problem wouldn’t be solved with a regular expression alone. Regular expressions are ways of writing patterns. You’re usually using them to determine if a string matches a particular pattern, or to find a particular piece of a string. You might use a regular expression to find “May” in “06-May-2020”, but the logic of what to do with it would be handled separately.
This is not something for the regex to do.
// How much milliseconds in 30 days?
const net = 1000 * 60 * 60 * 24 * 30;
// Date object can parse dates
const dateString = 'May 6 2020';
const date = new Date(dateString);
// Unfortunately we cannot just do date + net
// And have to convert latter into milliseconds first
const date_ms = date.getTime();
// Now math
const newDate_ms = date_ms + net;
// Parse new date
const newDate = new Date(newDate_ms);