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

  • SEARCH
  • Home
  • 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 9200131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:41:50+00:00 2026-06-17T22:41:50+00:00

I have function that loops every 500ms, and collects date information: var mlptoday =

  • 0

I have function that loops every 500ms, and collects date information:

var mlptoday = {};

var timer = setTimeout(today,500);

function today(){
    var d = new Date()
    mlptoday.date = checkTime(d.getDate()); //output: "27"
    mlptoday.year = d.getFullYear(); //output: "2013"
    mlptoday.month = checkTime(d.getMonth()+1); //output: "01"
}

function checkTime(i) { if (i<10){i="0" + i} return i }

In a different function, I would like to check if the date the user gives as input is either the same day, or after the given day.

An example input may be: 2013.01.27.

I use this snippet of code to achieve what I want:

var remTime = "2013.01.27"; //user input
var remTimeArray = remTime.split('.') //output: ["2013","01","27"]
if (
    !(remTimeArray[0] >= parent.mlptoday.year &&
    remTimeArray[1] >= parent.mlptoday.month) ||
    !((remTimeArray[1] == parent.mlptoday.month) ? Boolean(remTimeArray[2]*1 >= parent.mlptoday.date) : true)
){
    //the input date is in the past
}

As you could probably guess, this does not work. The conditional statement seems to fail me, because if I invert Boolean(...) with an !(...), it will never fire the error, otherwise it always will.

Here’s a snippet, where it works at it should:

var mlptoday = {};

var timer = setTimeout(today,500);

function today(){
    var d = new Date();
    mlptoday.year = d.getFullYear(); //output: "2013"
    mlptoday.month = checkTime(d.getMonth()+1); //output: "01"
    mlptoday.date = checkTime(d.getDate()); //output: "27"
    
    $('#values').html(JSON.stringify(mlptoday));
}


function checkTime(i) { if (i<10){i="0" + i} return i }

$(document).ready(function(){
    $('form').submit(function(e){
        e.preventDefault();
        var remTime = $('input').val(); //user input
        var remTimeArray = remTime.split('.') //output: ["2013","01","27"]
        if (
            !(remTimeArray[0] >= mlptoday.year &&
            remTimeArray[1] >= mlptoday.month) ||
            !((remTimeArray[1] == mlptoday.month) ? Boolean(remTimeArray[2]*1 >= mlptoday.date) : true)
        ){
            $('#past').fadeIn('fast').delay(500).fadeOut('fast');
        }
    })
})
#past { display:none; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<form>
    <input type="text" id="input" required autocomplete="off" placeholder="yyyy.mm.dd" pattern="^(19|20)\d\d[.](0[1-9]|1[012])[.](0[1-9]|[12][0-9]|3[01])$" required="" />
    <button>Check</button>
</form>
<pre id="values"></pre>
<span id="past">the input date is in the past</span>

I need a better way to do this, and I don’t want to use any date picker plugins.

  • 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-17T22:41:51+00:00Added an answer on June 17, 2026 at 10:41 pm

    I would compare the dates as integers to avoid complex logic.

    var todayConcat = "" + parent.mlptoday.year + parent.mlptoday.month + parent.mlptoday.date;
    var remTimeConcat = remTime.replace(/\./g, "");
    if (remTimeConcat < todayConcat) {
      //the input time is in the past
    }
    

    Just make sure the dates and months always have the leading zero.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code that looks like this: var baseClass = function() { // CODE
I have some code that looks like this: var MyObject = function () {
I have a simple function that loops while there are still elements in a
I have a function that gets some notifications, loops through them and the adds
I have a function that loops on itself. I'm still wrapping my head around
I have a while() function that loops a row of data within my table.
I have a callback function for another function that loops through the comments of
i have a function that looks like this. function startChatSession($items) { foreach ($test as
I have a simple function that looks at an incoming mySQL data type and
I have a autoload function that looks like so: function __autoload_HTTP_Client($class_name) { $HC =

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.