Solved

DateTime question

Posted on 2014-09-22
5
142 Views
Last Modified: 2014-09-25
I am trying to create a condition for scheduling interface. But there is also a rule behinf it .

Once a session is scheduled, students may change or cancel up to five (5) calendar days before the scheduled session. The five days are worked out to the minute the session starts. Once the student is inside the five (5) calendar day window (up to the minute) prior to a scheduled time, the session cannot be rescheduled or cancelled. Please be sure that the selected sessions are sessions that will be attended by the student

How would I implement that
0
Comment
Question by:erikTsomik
  • 3
  • 2
5 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 40337481
Take the scheduled date and time and subtract 5 days to get the cutoff date. Then compare the current date and time now to the cutoff date, down to the minutes. If it's later (ie they're within the 5 day window) don't allow any changes.

<cfset cutoffDateTime = dateAdd("d", -5, theScheduledDateTime)>
<cfif dateCompare(now(), cutoffDateTime , "n") gte 0>
	inside five day window. no changes allowed
<cfelse>
	changes allowed. before five day window. 
</cfif>

Open in new window

0
 
LVL 19

Author Closing Comment

by:erikTsomik
ID: 40337572
is DateCompare is a good command to use. is DateDiff is better?
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40337615
They do different things, so .. it all depends on the task. In this case, DateCompare is better IMO. You don't care about the number of minutes difference ... just whether or not the current date and time is before the cutoff date.
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 40337646
well in my case I do care about the time portion
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40337685
Right. What I meant was, while you could do the same thing with DateDiff, it it's more complicated than necessary. Since you do care about the time portion, you'd have to calculate the number of minutes (or seconds) difference between the two dates:

            minutesDiff = dateDiff( date1, date2, "n");

Then use a formula to figure out how many minutes are in 5 days

      ie minutesIn5Days = 60 min per hour * 24 hours per day * 5 days.  

Then determine if #minutesDiff# is less than #minutesIn5Days#

Why do all that conversion logic, when you do not really care exactly how many minutes are in 5 days... You just want to know if the current date falls within the window or not.  The conversion stuff just makes the code more complicated IMO.  

Since the business rule is within 5 days, using dateAdd("d[ays]", -5, ..)" is easier to follow than a bunch of code converting time units. This does the same thing, more intuitively IMO:

     <cfset cutoffDateTime = dateAdd("d", -5, theScheduledDateTime)>
     <cfif dateCompare(now(), cutoffDateTime , "n") gte 0>
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Tool to email me when a website changes 29 120
apply ddos protection on all network interface 2 92
ColdFusion 10 Error 2 37
setup wamp server for first time 2 46
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
The viewer will learn how to count occurrences of each item in an array.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now