1

I have this array:

["2018-01", "2018-02", "2018-03", "2018-04", "2018-05", "2018-06", "2018-07", "2018-08"]

And this code is suposed to seak if a date is between the start/end but is not working:

array.forEach(function(item){ //console.log(item) var a = moment(item); var start = a.format('YYYY-MM-DD') var b = a.add(30, 'days'); var end = b.format('YYYY-MM-DD') console.log("procesing search between date : ",start , " and last date: ", end) letrado.forEach((value, key) => { //console.log("1-key =>", key, "1-value =>", value.compra_fecha_oper); let polo = moment(value.compra_fecha_oper).format('YYYY-MM-DD') var tonto = moment(polo).isBetween(String(start), String(end) ); // true if ( tonto = true ){ console.log(key, " Value Date: ",value.compra_fecha_oper ,"Has result: ", tonto) } }); }); 

The result is a very long list like this:

enter image description here

But if you try this like concept:

 var isbetween = moment('2015-05-15').isBetween('2015-05-01', '2015-05-31'); console.log("valor de isbetwen",isbetween ) 

Is working.

What is wrong with the code?

1
  • 1
    if ( tonto = true ){ you mean if ( tonto == true ){ or if ( tonto === true ){ ... since if ( tonto = true ){ is ALWAYS true as you assigned it to be true (= is assignment, not equality check) Commented May 3, 2020 at 22:34

1 Answer 1

1

This line is the isssue,

if ( tonto = true ){ 

This should be triple equal to

if ( tonto === true ){ /* or simply */ if ( tonto ){ 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I had not noticed

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.