XJS: how to compare dates to check if within 24 hrs

I want to write a small function that takes in 2 date/time parameters in the following format:
flightDate =    2015-05-14T09:30
currentDate = 2015-05-13T19:41

And I want to compare date/time and make sure that flightDate is not within 24hrs of currentDate. if yes, throw error.
badtz7229Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobOwner (Aidellio)Commented:
Use the moment.js framework: http://momentjs.com/docs/#/parsing/

var flightDate =    moment("2015-05-14T09:30");
var currentDate = moment("2015-05-13T19:41");

var d = flightDate.diff(currentDate, "hours");

if (d <= 24) {
 alert("error...");
}
0
badtz7229Author Commented:
I'm getting that "diff" is not a function.
is there a way to implement the diff function for my purposes?
0
RobOwner (Aidellio)Commented:
Yes because you need to include the moment library.
See this demo http://jsbin.com/xawimujunu/1/edit?js,console,output
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

badtz7229Author Commented:
without importing libraries can this be done?
0
RobOwner (Aidellio)Commented:
It can but you need to parse the days yourself

What have you done do far?
0
badtz7229Author Commented:
all I had done was

                          if (flightDate .toString() < currentDate .toString())
                                  bSameDay = true;

but this was only comparing dates. not time.
0
RobOwner (Aidellio)Commented:
If you're having trouble now it's only going to get harder to parse the dates. A library is just JavaScript, nothing special, you just put this at the top if your page in the head section:

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.2/moment.min.js"></script>

And then use their code I've posted previously. With your level of knowledge, I suggest this is the only way for you.

More on JavaScript frameworks http://www.experts-exchange.com/articles/12264/Javascript-Frameworks-what-are-they.html
0
badtz7229Author Commented:
I didn't end up using any of the suggestions (though good ones).
Instead I built my own function to calculate
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
badtz7229Author Commented:
I created a function to calculate dates. I do not have access to those built in functions in my environment that were suggested
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.