Skip to main content
Participant
November 16, 2010
Question

Embarrasing question

  • November 16, 2010
  • 2 replies
  • 616 views

It's kind of embarassing to ask this simple question, I'm trying to do this:

I need to run my codes (app) Monday through Friday only. Saturday and Sunday the app. should or can not be run

I read, by default CF set Saturday is day 7 and Sunday as day 1:

<CFIF #DayOfWeek(Now())# IS "1">

  <cfabort>

<CFELSEIF #DayOfWeek(Now())# IS "7">

  <cfabort>

<CFELSE>

<!---  run the program --->

</CFIF>

I like the following but not sure which one it correct:

<CFIF #DayOfWeek(Now())# IS "1"  OR  #DayOfWeek(Now())# IS "7"  >

   <cfabort>

<CFELSE>

<!--- Run the program --->

</CFIF>

OR

<!--- does AND operator means both conditions need to be evaluated at the same time? Saturday and Sunday will never co-exist at the same time so this should be incorrect ? --->

<CFIF #DayOfWeek(Now())# IS "1"  AND  #DayOfWeek(Now())# IS "7"  >

   <cfabort>

<CFELSE>

<!--- Run the program --->

</CFIF>

This topic has been closed for replies.

2 replies

ecobb
Inspiring
November 16, 2010

If you'd rather do it without all of those if/elseif statements, you could do something like:

<!--- create a list of the days you want to abort -->
<cfset daysNotToRun = "1,7">
<cfif ListFind(daysNotToRun,DayOfWeek(Now()))>
     <cfabort>
</cfif>

That way, if you ever decide to add another day to the abort list, just put the number in the list and you're done, no need to add another elseif statement.  But, as Ray said, your first example is fine.

Inspiring
November 16, 2010

You might find it worth your while to change the overall logic from "abort on a bad day" to "run on a good day".  That way if it ever got included as part of another job, the abort wouldn't mess things up.

Depending on your situation, you may also want to take an entirely different approach to identifying good and bad days.  If your business requirements dictate that holidays are also bad days, you'll probably want to store holiday info in a database somewhere.

cfjedimaster
Inspiring
November 16, 2010

Your first one was fine.

Note - you don't need all the # signs.