Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8866547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:48:45+00:00 2026-06-14T16:48:45+00:00

Here I have a function which I use to calculate the difference between two

  • 0

Here I have a function which I use to calculate the difference between two Time variables, start and end, and display the output as ‘Past’, ‘Current’, or ‘Future’.

I was able to calculate ‘Current’ and ‘Future’ values, but no luck with “Past’. Here is the jsFiddle and any help would be great.

On a side note, I do prefer a plugin-less way to achieve this.

//My Start time and End time
var start = "Mon Nov 22 2012 08:45:00 GMT+0800 (Malay Peninsula Standard Time)";
var end = "Mon Nov 22 2012 10:15:00 GMT+0800 (Malay Peninsula Standard Time)";

//Calling to test function
test(start, end);

//Function to calculate 
function test(startTime, endTime) {
    startTime= new Date(startTime);
    endTime= new Date(endTime);
    var currentTime = new Date();
    var difference = currentTime - startTime; 

    if (difference > 0 && currentTime > startTime) {
        alert ("Past!");
    } 

    if(startTime < currentTime && currentTime < endTime){ 
        alert("Current!");
    }

    if(difference < -1){
        alert("Future!");
    }
}​

Link to jsFiddle

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:48:47+00:00Added an answer on June 14, 2026 at 4:48 pm

    Sigh!! I just need some sleep. It’s working and here’s the updated jsFiddle: http://jsfiddle.net/9jk6a/9/

    Thanks everyone who helped.

    //My Start time and End time
    var start = "Mon Nov 23 2012 08:45:00 GMT+0800 (Malay Peninsula Standard Time)";
    var end = "Mon Nov 23 2012 10:15:00 GMT+0800 (Malay Peninsula Standard Time)";
    
    //Calling to test function
    test(start, end);
    
    //Function to calculate 
    function test(startTime, endTime) {
        startTime= new Date(startTime);
        endTime= new Date(endTime);
        var currentTime = new Date();
        var difference = currentTime - startTime; 
    
        if (startTime < endTime && endTime < currentTime) {
            alert ("Past!");
        } 
    
        if(startTime < currentTime && currentTime < endTime){ 
            alert("Current!");
        }
    
        if(currentTime < startTime && startTime < endTime){
            alert("Future!");
        }
    }​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function in PHP which calculates the distance between two places. Here
I have a javascript function which I wants in PHP, Here is my JavaScript
I have a function which takes two arrays containing the tokens/words of two texts
Here I have declared another virtual function in Derived class. #include <iostream> using namespace
I have the function prototype here: extern C void __stdcall__declspec(dllexport) ReturnPulse(double*,double*,double*,double*,double*); I need to
I have a function that uses the Google Blobstore API, and here's a degenerate
The question I have here is for some reason when the getInboxUnreadMessagesCount js function
Just a little confused here... I have a function in postgres, and when I'm
Here is a jQuery slide function I have applied to a div on hover
We have system here that uses Java JNI to call a function in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.