Solved

DateTime question

Posted on 2014-09-22
5
146 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

740 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