tags:

views:

39

answers:

3

Hey guys,

Sorry the above is a little vague it's rather hard to word. I've got a simple CFIF statement in my code to set datesup to be either "st", "nd", "rd" or "th" as appropriate.However, when the code is run, it just sets datesup to be "st" and nothing else.

Code is below.

     #DATEFORMAT(date, "dddd")# the #DATEFORMAT(date, "dd")#
                        <cfset dateday = #DATEFORMAT(date,"dd")#>
                        <cfif dateday eq 01 OR 21 OR 31>
                            <cfset datesup = "st">
                        <cfelseif dateday IS 01 OR 11>
                            <cfset datesup = "nd">  
                        <cfelseif dateday IS 03 OR 23>
                            <cfset datesup = "rd">      
                        <cfelse>
                            <cfset daatesup = "th">     
                        </cfif>
                        #datesup# of #DATEFORMAT(date, "mmmm, yyyy")#

Any ideas?

Thanks for the help and sorry again if I've been too vague.

Jake

+1  A: 

Hey Jake,

The OR 21 is evaluating to true. You'd need to change it to -> <cfif dateday eq 01 OR dateday eq 21 or dateday eq 31>

You could also use <cfif right( dateday , 1 ) eq 1>

The variable for "th" should be datesup, you have an extra a there.

Bradley Moore
Thanks for the heads up ref daatesup and why it's evaluating to true! Much appreciated.
Jake Hendy
+3  A: 

Your expression means:

if ( dateday == 01 ) or ( 21 ) or ( 31 )

Since 21 and 31 convert to true, the condition is true.

You need

if dateday eq 01 or dateday eq 21 or dateday eq 31

Or

if listFind( '01,21,31', dateday )

Sean Corfield
Thanks for the listFind idea!
Jake Hendy
+5  A: 

You can't do...

cfif dateday eq 01 OR 21 OR 31

It should be...

cfif dateday eq 01 OR dateday eq 21 OR dateday eq 31

All the numbers are evaluated as true so just doing OR 21 is the same as doing OR true.

Also, ColdFusion provides a Day(now()) function you can use rather than dateformat.

remotesynth
Thanks for the answer and why it evaluates to true!
Jake Hendy