• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

conditional code to highlight an upcoming activity from a cfouput query

New Here ,
Mar 21, 2023 Mar 21, 2023

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--->

table.jpg

Views

110

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 22, 2023 Mar 22, 2023

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>#
...

Votes

Translate

Translate
Community Expert ,
Mar 22, 2023 Mar 22, 2023

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 23, 2023 Mar 23, 2023

Copy link to clipboard

Copied

LATEST
This is exactly what I was looking for. Thank you for your help. The converting to a date object I have not used yet. But this will be now in my catalog for such.
Thanks again for your help.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation