Since I started using CF years ago, Im struggling with the dateCompare and dateDiff functions. Every time when one of them crosses my path I promise myself to remember the solution for next time. But
As Time Goes By
i forget about them until I need one of the two again, like this morning.
The second one, as you probably understand, is created when a visitor submit a form. From the moment Session.reviewTime exist I would like to output a message for about 20 minutes. This is what I tried:
It will be a full timestamp date/time object, but it will contain the time as well (for where the CF server exists, mind you)
As far as the logic goes, I would say:
<cfif structKeyExists( session, “reviewTime” ) and now() gt dateAdd( “n”, 20, currentTime )>
<!— It is beyond the 20 minute marker.—>
<cfelse>
<!— It is still within the 20 minute marker. (or session.reviewTime doesn’t exist) —>
</cfif>
Thank you for the response. You’re absolutely right about the currentTime variable but I had It like that since I was/and still am struggling with the logic.
Your logic made me think though, but it is still not how it should be. You have:
<!---
Set this to a time that is either outside of 20 minutes from now
or inside 20 minutes from now.
--->
<cfset datThen = createDateTime( 2010, 12, 4, 12, 15, 0 ) />
<cfif isDefined( "datThen" )>
<cfif now() lt dateAdd( "n", 20, datThen )>
<p>It has been less than 20 minutes since time set.</p>
<cfelse>
<p>It has been over 20 minutes since time was set.</p>
</cfif>
<cfelse>
<p>Variable 'datThen' does not exist.</p>
</cfif>
I did a quick test and this works flawlessly. When I set the first variable to a value that is 20 minutes from now, it reports properly. When I set it to a time later than that, it reported properly. When I changed the variable so it doesn’t exist, it told me so.
Aaron thank you again for your response. You’re absolutely right. I wonder what I was thinking in the first place The logic was simply not there when I wrote my first message and the reply to your first message. There is and has been there all the time a timestamp in the reviews table review_date and I simply didn’t think of using that one so now i basically use what you said all along
Everything is working fime now Aaron, thank you again About code use in the forum if you post or reply to a post on the second row of the text editor all the wy to the right is a drop down(Select Syntax). There are more than one way of using the tags. You can first place a tag and after that paste your code within the opening and closing tag or you add your code, select the code and then choose the appropriate tag.
By the way about what you said about having a second person looking at your code, I like that idea myself as well. So I hope I keep you to that. There are those times, that under a lot of stress and time pressure, you even don’t see the simplest mistakes any longer
I hear ya. At work, I have 1 other web developer. And when we get stuck, we give it some time to work it out on our own. But if we can’t move forward, we get the other person in there.
On days when that person was out sick, I could spend freaking hours of wasted time trying to find the issue. Very frustrating.