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
Solved

DateTime question

Posted on 2014-09-22
5
145 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

839 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