Skip to main content
July 29, 2009
Answered

CFIF between certain hours

  • July 29, 2009
  • 4 replies
  • 3786 views

Hi

I would like to use cfif time is between 12:00:00 and 04:00:00

my date and time is saved in  variable datedate1

<cfset datedate1=#DateFormat(newTime,"yyyy-mm-dd hh:mm:ss")#>

any help would be appreciated

Thanks!

    This topic has been closed for replies.
    Correct answer -__cfSearching__-

    JulesSon wrote:

    sorry need it to be between 12:00 am (midnight) and 4:00 am

    Thanks!

    As suggested by Dan, use the results of the datePart function in your comparison. DateFormat and TimeFormat return strings. DatePart returns an integer. Comparing numbers (not strings) will produce the most consistent and accurate results.

    4 replies

    Participant
    July 29, 2009

    <cfif dateDate1 GTE 00 and dateDate1 LTE 04>

    Inspiring
    July 29, 2009

    Are you sure that what you said is what you mean?  I'm reading it as between noon and 4 am.

    In addition to the other answers, the datepart() function can be used.

    July 29, 2009

    sorry need it to be between 12:00 am (midnight) and 4:00 am

    Thanks!

    -__cfSearching__-Correct answer
    Inspiring
    July 29, 2009

    JulesSon wrote:

    sorry need it to be between 12:00 am (midnight) and 4:00 am

    Thanks!

    As suggested by Dan, use the results of the datePart function in your comparison. DateFormat and TimeFormat return strings. DatePart returns an integer. Comparing numbers (not strings) will produce the most consistent and accurate results.

    Dileep_NR
    Inspiring
    July 29, 2009

    Hi

    <cfset dateDate = timeformat(now(),"h")>
    <cfdump var="#dateDate#">
    <cfif dateDate IS 12
            or dateDate IS 1
            or dateDate IS 2
            or dateDate IS 3
            or dateDate IS 4>
    Condition is true in both AM and PM
    <cfelse>
    Not
    </cfif>

    Participant
    July 29, 2009

    try

    <cfset dateDate1 = timeformat(NOW(), 'hh:mm')>
    <cfif dateDate1 GTE 12 and dateDate1 LTE 16>
    It is between 12 and 4
    <cfelse>
    Not
    </cfif>