Which operator should I use in the JavaScript c: if I want to be between two variables?

0

Gentlemen, I need to know which operator to use in Javascript's c: if when I want to make a decision between them, for example, I need a background of a Div to turn red when it is between date x and y, is the "ENTRE" operator, here is a snippet of my code.

<c:if test ="${realizadoVN dfim <> dtini && ${realizadoVN <metaVN}">
	<div class="container">
		<div class="marca" ><h1>VN</h1></div> 
		<div class="meta"style="font-size: 25px;">META: <fmt:formatNumber value = "${VN.rows[0].META}" type="currency"/></div>
		<div class="rel" style= "background-color:red; color:white; font-size:30px;">ACUMULADO <br><br><fmt:formatNumber value = "${realizadoVN}" type="currency"/><br><h1> <c:out value="${VN.rows[0].ACUMULADO}"/>%</h1></br></div>
	</div>
</c:if>
    
asked by anonymous 09.08.2018 / 21:23

1 answer

1

There is an excellent Javascript library called MomentJS to work with dates, here's an example:

var input = document.getElementById('dataInput');
var div = document.getElementById('minhaDiv');
  
var dini = moment().endOf('month').add(-7, 'd');
var dfim = moment().endOf('month');

document.getElementById('certoSpan').innerHTML = dini.format('DD/MM/YYYY')
document.getElementById('cuidadoSpan').innerHTML = dini.format('DD/MM/YYYY') + ' ~ ' + dfim.format('DD/MM/YYYY')
document.getElementById('ruimSpan').innerHTML = dfim.format('DD/MM/YYYY')

input.addEventListener('change', function() {
  var data = moment(input.value);
  

  
  if (data.isBefore(dini, 'd')) {
    div.style.backgroundColor = 'green';
    div.innerHTML = 'Tudo certo! :)';
  } else if (data.isBetween(dini, dfim, 'd', '[]')) {
    div.style.backgroundColor = 'yellow';
    div.innerHTML = 'Cuidado! :|';
  } else if (data.isAfter(dfim, 'd')) {
    div.style.backgroundColor = 'red';
    div.innerHTML = 'Deu ruim! :(';
  }
  
  

});
#minhaDiv {
  padding: 10px;
  margin: 10px;
  border: 2px solid #000;
  text-align: center;
  color: #000;
  font-weight: bold;
}
<script src="https://momentjs.com/downloads/moment.min.js"></script><divid="minhaDiv">MINHA DIV</div>
<input type="date" id="dataInput">
<p>Tudo certo até <span id="certoSpan"></span></p>
<p>Cuidado entre: <span id="cuidadoSpan"></span></p>
<p>Deu ruim depois de: <span id="ruimSpan"></span></p>
    
10.08.2018 / 18:11