Comparing Dates in JavaScript and ASP Classic

Related Query:
Using Javascript to compare two dates from strings, ensuring begin is less than or equal to end

Newbie here! I've created an HTML form featuring two date input fields that users can populate either manually or with a calendar picker. Specifically, these are the Start Date and End Date fields. Before allowing form submission, I need to implement a check to ensure that the End Date entered by the user is greater than or equal to the Start Date entered. I'm using Dreamweaver for this project. Any assistance on achieving this would be highly appreciated. Thank you!

Answer №1

Comparing Dates:

function checkDates(date1, date2) {
    var difference = date1.getTime() - date2.getTime();
    if(difference == 0) {
        return 0;
    }
    return difference > 0 ? 1 : -1;
}

Difference in Dates:

var startDay = new Date(),
    endDay,
    diff;

setTimeout(function() {
    endDay = new Date();
    diff = endDay.getTime() - startDay.getTime();
    alert(diff + ' milliseconds');
}, 1000);​

View Demo

Read Documentation

Answer №2

Consider trying out this code snippet for a similar solution (view the JSFiddle demo)

<script type="text/javascript">
    function checkDate(){
        var date1 = new Date(""+document.getElementById("date1").value);
        var date2 = new Date(document.getElementById("date2").value);
        alert(date2 > date1);
    }
</script>

<input id="date1" type="text" value="09/25/2012"/>
<input id="date2" type="text" value="09/24/2012"/>
<input id="checkBtn" type="button" value="Check" onclick="checkDate()"/>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Harness the power of Angular 2 CLI to create dynamic and interactive

I've exhausted all options available. I'm working with a very straightforward ng2 app. Here is the structure of the files: mean |- client (where the ng2 app is housed) | |- dist | |- (all ng2 app directories)... |- node_modules |- rou ...

Obtaining the data from the React material-UI Autocomplete box

I have been exploring the React Material-UI documentation (https://material-ui.com/components/autocomplete/) and came across a query. Within the demo code snippet, I noticed the following: <Autocomplete options={top100Films} getOptionL ...

Error: When using the axios package in TypeScript code within a Firebase cloud function, there is an issue with reading the property 'post' which is undefined

I am attempting to implement the following logic in a Google Cloud Function. When I run this function using the emulator, I consistently encounter the error message ⚠ functions: TypeError: Cannot read property 'post' of undefined I have tried ...

AngularJS UI Router: Best Practices for Including the Controller Script

I have created a basic AngularJS single page application that uses UI Router to navigate between two views. When the user clicks on the Home link, they should see a line of text. Similarly, clicking on the About link should display some text as well, but i ...

Issue: Query.get unsuccessful - Initial parameter should be an object

Dealing with Firestore in React Native. Encountering the following issue: Error: Query.get failed: First argument must be an object Attempting to retrieve User data from another collection (Item), but it doesn't seem to be working as expected. e ...

CSS Flexibility

Greetings everyone, it's been a while since I dabbled in web development. I recently worked on my site with the intention of making it responsive using flexbox. This is my first time posting here, so please guide me on how to seek help more effective ...

Discovering an Ajax request and converting it to a regular request in Node.js

Hey there! I have the following code snippet and I am curious to learn how to differentiate between an ajax request and a normal request without using Express. var http = require('http'); var fs = require('fs'); var path = require(&apo ...

How to use hooks in NETXJS to pass data from a page to a component

Hey there, how are you doing? I am currently working on a project using Next.js and styled components. I am trying to change a string using props in my layout component, where the main content is dynamic per page. Page 'prueba.js' import React f ...

I'm having trouble getting my accordion menu to work properly. Whenever I click on the question title, the answer doesn't seem to show up or collapse. What could be causing this issue?

I am currently working on a project to create an accordion menu where the answers are hidden and only revealed upon clicking the question. However, when I test it out, nothing happens when I click on the question. Here is my code: .accordion-Section ...

Error: Unable to locate module: 'readline'

I've encountered a Module not found: Can't resolve 'readline' issue with an NPM package that is installed and seems to be present in the node_modules directory. The error occurs at: module "c:/Users/ts-lord/Desktop/server/cdr-ui/node ...

Tips for passing an additional parameter to a function within the map method in JavaScript

Is there a way to pass an additional parameter to the aggregationFunction in JavaScript when using dataArray.map(self.aggregationFunction)? I attempted using .bind(extra parameter) but it didn't yield the desired result. Any advice would be appreciate ...

Should one use Javascript library dependencies with or without bundling?

I'm in the process of packaging a library so that it can be utilized in two different ways: <script src="myLib.js"/> as well as mylib = require('myLib') However, myLib relies on several other libraries, some of which I believe the ...

Childnode value getting replaced in firebase

Every time I attempt to push values to the child node, they keep getting overridden. How can I solve this issue and successfully add a new value to the child node without being overwritten? ...

"Fill the designated area on the webpage with data retrieved from an external script

In my current project, I am utilizing Angular and JQuery to enhance re-usability by setting the header and footer as partials. However, I encountered an issue where I needed certain javascript functions to be executed within the footer upon loading - a tas ...

How to trigger a Switch when the input of a dynamic form changes in Vue.js

After I asked this previous question, another one came to mind: How to disable button if multiple form inputs do not change in Vue.js Each form has a switch. When the form inputs are changed, the switch should go from an OFF state to an ON state. I achiev ...

Effective methods for transferring parameters between two separate JavaScript files within an express.js application

Currently, I am working with Express.js and facing a challenge in passing parameters from one JavaScript file to another. How can this be accomplished? The two files involved are 1. process.js var WebPageTest = require('webpagetest'); var wpt ...

I am unable to access my JavaScript class in Laravel Mix

Within my Laravel project, I have developed a custom form validation class. However, after running npm run dev, I am unable to access this class. Files: small-form-validation.js class SmallFormValidator { errMsgs = { required: 'This fiel ...

What could be causing this three.js code to not function properly when being run from a local

I'm a beginner with three.js. I downloaded this page as an HTML file from Firefox to my desktop. All the related files (threejs, statsjs, helvetiker_bold js, detecterjs) were saved successfully. However, the animation is not working and there are no e ...

Maximizing Efficiency with React.js Search Bar API

As someone who is very new to JavaScript and the realm of React, I have been diving into hooks. However, when attempting to fetch an API for a search bar feature, things didn't quite go as planned. My goal is to retrieve data from a URL (which happen ...

Resolving the Persistence Problem of Navigation Bar Fading In and Out

I've been struggling for hours trying different methods to achieve the desired outcome, but unfortunately, none of them have worked as expected. My goal is simple: I want the fixedbar to fade in when the scroll position exceeds the position of the ph ...