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 6335123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:47:41+00:00 2026-05-24T18:47:41+00:00

Im tyring to compare two dates in javascript but im getting strange values when

  • 0

Im tyring to compare two dates in javascript but im getting strange values when calculating the dates.

Can anyone see anything obvious in my code that is causing the issue?

The problem is the Todays date variable looks like a normal date, but my calculation for next week and last week are coming out as large numbers and the comparison wont work.

//Handles client side date selection changed
function dateSelectionChanged(sender, args) {

    //Declare array for Day names
    var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

    //Get the date
    var date = sender.get_selectedDate();

    //Get todays Date
    var today = new Date();
    var nextWeek = new Date().setDate(today.getDate() + 7);
    var lastWeek = new Date().setDate(today.getDate() - 7);

    //Show the day name
    $('#<%= txtDay.ClientID %>').val(days[date.getDay()]);

    if ( date < lastWeek ) {
        alert('Date Under Week');
    }
    if ( date > nextWeek ) {
        alert('Date Over Week');
    }
}

And here is the Code in Debug so you can see the values:
enter image description here

EDIT:
Solution

//Handles client side date selection changed
function dateSelectionChanged(sender, args) {

    //Declare array for Day names
    var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

    //Get the date
    var date = sender.get_selectedDate();

    //Get todays Date
    var today = new Date();
    var nextWeek = new Date().setDate(today.getDate() + 7);
    var lastWeek = new Date().setDate(today.getDate() - 7);

    //Get the dates in easier to compare format
    nextWeek = new Date(nextWeek);
    lastWeek = new Date(lastWeek);

    //Show the day name
    $('#<%= txtDay.ClientID %>').val(days[date.getDay()]);

    if ( date < lastWeek) {
        alert('Date Under Week');
    }
    if ( date > nextWeek) {
        alert('Date Over Week');
    }
}
  • 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-05-24T18:47:42+00:00Added an answer on May 24, 2026 at 6:47 pm

    For setDate, JavaScript returns timestamps, which represent the amount of milliseconds since 1 January 1970 00:00:00 to a specific moment in time. It might look useless, but in fact is very useful as you can represent any time as a simple number.

    In case you want to get back a Date, you can use:

    new Date(timestamp);
    

    so e.g. add:

    nextWeek = new Date(nextWeek);
    lastWeek = new Date(lastWeek);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to compare two datetimes but I can't get it to work. public
I am trying to compare two dates. I have this code which I thought
I am trying to compare two decimal values in Java script. I have two
I am trying to compare two strings in Smalltalk, but I seem to be
Possible Duplicate: Compare 2 dates with JavaScript I haven't done much JavaScript. I am
I trying to compare two dates (DateTime) in nHibernate linq: query = query.Where(l =>
I'm trying to compare two strings with each other on the iphone, but the
I am trying to compare two strings in VB but compareTo, compare, equals etc
Hi im trying to compare two dates in MySQL via a query, one is
I am having a problem when i am trying to compare two dates in

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.