Search code examples
datecoldfusioncfmlcoldfusion-2018

Dates not equal to numbers


I don't want this to be true

<cfset somedata = "12:00 AM">

<cfif "12:00 AM" EQ 0>
    Wow
</cfif>

Most of the time somedata has numbers. But it can have time. If it has 12:00 AM, I don't want this if statement to return as true.


Solution

  • You can use code like below ( Add condition isNumeric(somedata)), It will check somedata EQ 0 condition only when the somedata is numeric.

    <cfset somedata = "12:00 AM">
    
    <cfif isNumeric(somedata) AND somedata EQ 0>
        Wow
    </cfif>
    

    For your scenario ( somedata = "12:00 AM" ) somedata is not numeric, so that time ( isNumeric(somedata) ) condition will failed. It will not go under if condition.