Avatar of hefterr
hefterr
Flag for United States of America asked on

Comparing the Time in ColdFusion

Hi Experts,
I know this must sound simple - but these are the ones I get hung up on.

I have a program where I want to see if the current time is after 6 am (or inversely between 12 midnight and 5:59.9999 am of the current day.

Do you use Datediff?, Datecompare?

Thanks in advance,
hefterr
ColdFusion Language

Avatar of undefined
Last Comment
_agx_

8/22/2022 - Mon
_agx_

Use datePart to get the hour.

<cfif datePart("h", now()) lt 6>
      it's before 6AM
<cfelse>
    it's on or after 6AM
</cfif>
hefterr

ASKER
Hi agx,
For extra credit :)
How would I tell if the current time is after 6:15 am?

Thank again!
ASKER CERTIFIED SOLUTION
_agx_

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
hefterr

ASKER
Thanks much!  When I googled this I saw involved solutions.  Yours are more elegant.

I owe you another 50 points for the extra credit :)
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
_agx_

I love how date/time stuff usually turns out to be simpler than you think. Three cheers for date/time functions :)