I am a beginner. I'm am trying to create a function that simply switches texts. When the due date set has been reached, the text displayed would be "Expired"; if this date hasn't be reached, the text remains as "Active" . If there is a better way to do this, I'd appreciate it.
The problem I have is that the date is saved as a string in my database and I want to know if there is a way to convert this to a normal date format.
Here's what I've tried and the logic I followed. Any help would be greatly appreciated.
var exp_date = document.getElementById("datex").value = test;
var today_date = new Date().toLocaleDateString();
var state1 = ` <div class="valida-table-field estatuto validado">
<div>Active</div>
</div>
`
var state2 = ` <div class="valida-table-field estatuto rejeitado">
<div> Expired </div>
</div>`
function state() {
if (today_date != exp_date) {
document.getElementById('disp_state').innerHTML = state1
} else if (today_date = exp_date) {
document.getElementById('disp_state').innerHTML = state2
}
}
<div class="valida-table-field data" id="datex">
<div>[[${ order.date }]]</div>
</div>
<div id="disp_state">
<!-- Display Text here -->
</div>