Link to home
Start Free TrialLog in
Avatar of hefterr
hefterrFlag 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
Avatar of _agx_
_agx_
Flag of United States of America image

Use datePart to get the hour.

<cfif datePart("h", now()) lt 6>
      it's before 6AM
<cfelse>
    it's on or after 6AM
</cfif>
Avatar of 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
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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 :)
I love how date/time stuff usually turns out to be simpler than you think. Three cheers for date/time functions :)