I am trying to create the datatable thead time accordingly, but I am having trouble when saving the day shift, changing from AM-PM OR PM-AM.
I want when the condition is D it means it's the day shift and the thead should start from 9AM-9PM; when the condition is N it means it's night shift and the thead should start from 9PM-9AM.
<table class="table" id="mytable">
<thead>
<tr></tr>
</thead>
</table>
function load_table(status) {
$("table#mytable thead tr").empty();
let initTime = 0 - 3;
let startTime = 9;
if (status == "D") {
for (var i = 0; i < 13; i++) {
$("table#mytable thead tr").append(`
<th>${startTime} - ${startTime+1 <= 12 ? startTime+1 +"AM" : initTime+"PM"} </th>
`);
startTime++, initTime++;
}
} else {
for (var i = 0; i < 13; i++) {
$("table#mytable thead tr").append(`
<th>${startTime} - ${startTime+1 <= 12 ? startTime+1 +"PM" : initTime+"AM"} </th>
`);
startTime++;
}
}
}
load_table("N");
// D = DAY & N = Night
// Day = 9AM - 9PM
// Night = 9PM - 9AM
statusis "D" or "N"?startTimeis always 9, so start the night shift withi = 12. You'll need to add code that resetsstartTimeto 0 at midnight. I'm not sure whatinitTimeis supposed to be, starting at -3...