开发者

CFIF Stucture refuses to work. Always uses first statement

开发者 https://www.devze.com 2023-01-12 18:00 出处:网络
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

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>
                            开发者_Python百科<cfset daatesup = "th">     
                        </cfif>
                        #datesup# of #DATEFORMAT(date, "mmmm, yyyy")#


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.


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 )


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消