Copy link to clipboard
Copied
I am outputting the results of a query that shows the person who are scheduled to come to work, the date that they are working, the times that they should be in, and the shift number. I am having difficulties trying to highlight the upcoming day if that day is within seven days of the current date. The conditional code that I am using either highlights all the dates or doesn’t highlight. Any dates at all. I know that there is a way to do it. I am just stuck. i've attached an image of the result that im looking for. Any help would be great. Please see my code below.
My initial query
<cfquery name="security_admin" datasource="master">
select <!---concat(fname,' ',xholyabbv) as FOI,---> concat(fname) as FOI, cell, squadlt, secfoiid, secid, secdate as DATE, secshift, shift.shift as TIMES, shinumber, shiweek, lt_initials
FROM name
LEFT JOIN security ON foiid = secfoiid
LEFT JOIN shift ON shiid = secshift
LEFT JOIN squadlt ON ltid = squadlt
WHERE secfoiid is not null
AND secdate between '#secstartdate#' and '#secenddate#'
ORDER BY shinumber, date <!---times desc,--->;
</cfquery>
<cfquery name="week_security" datasource="master">
Select weeid, weebegin, weeend
from week_security
</cfquery>
<cfquery name="week_security" datasource="master">
Select weeid, weebegin, weeend
from week_security
</cfquery>
<!---my table that display the results--->
<div class="container-md">
<table id="example" class="display table-sm" >
<thead>
<tr>
<th>Shift No.</th>
<th width=".5%">Date</th>
<th width="20%">Brother</th>
<th width="20%">Time</th>
<th width=".5%">Squad</th>
</tr>
</thead>
<tbody>
<cfloop query="security_admin">
<cfoutput>
<tr>
<td align="center">#shinumber#</td>
<td><cfif now() lTE "#week_security.weeend#" and now() gTE "#week_security.weebegin#">***<cfelse></cfif>
#LsDateFormat(date, 'mm/dd')#</td>
<td>#security_admin.foi#</td>
<td>#security_admin.times#</td>
<td>#security_admin.lt_initials#</td>
</tr>
</cfoutput>
</cfloop>
</tbody>
</table>
</div>
<!---My disired outcome--->
Suggestion:
<!--- Replace the 2 tags <cfloop> and <cfoutput> with just the 1 tag <cfoutput> --->
<cfoutput query="security_admin">
<!--- Convert to a date object, which is more accurate to handle --->
<cfset scheduleDateObject=LSParseDatetime(date)>
<!--- Evaluate difference in days from today --->
<cfset dateDiffInDays=dateDiff("d", now(), scheduleDateObject)>
<tr>
<td align="center">#shinumber#</td>
<!--- Bold, red asterisks added when schedule date is within 7 days of today --->
<td>#
...
Copy link to clipboard
Copied
Suggestion:
<!--- Replace the 2 tags <cfloop> and <cfoutput> with just the 1 tag <cfoutput> --->
<cfoutput query="security_admin">
<!--- Convert to a date object, which is more accurate to handle --->
<cfset scheduleDateObject=LSParseDatetime(date)>
<!--- Evaluate difference in days from today --->
<cfset dateDiffInDays=dateDiff("d", now(), scheduleDateObject)>
<tr>
<td align="center">#shinumber#</td>
<!--- Bold, red asterisks added when schedule date is within 7 days of today --->
<td>#LSDateFormat(scheduleDateObject, 'mm/dd/yyyy')# <cfif dateDiffInDays LTE 7><span style="color:red;font-weight:bold;">***</span></cfif></td>
<td>#security_admin.foi#</td>
<td>#security_admin.times#</td>
<td>#security_admin.lt_initials#</td>
</tr>
</cfoutput>
Copy link to clipboard
Copied