?
Solved

DateTime question

Posted on 2014-09-22
5
Medium Priority
?
152 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 2000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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.
What You Need to Know when Searching for a Webhost Provider
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

777 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