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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:01:36+00:00 2026-05-14T05:01:36+00:00

I used the following function: function datediff() { var dat1 = document.getElementById(‘date1’).value; alert(dat1);//i get

  • 0

I used the following function:

function datediff()
{
  var dat1 = document.getElementById('date1').value;
  alert(dat1);//i get 2010-04-01
  var dat2 = document.getElementById('date2').value;
  alert(dat2);// i get 2010-04-13
 
  var oneDay = 24*60*60*1000;   // hours*minutes*seconds*milliseconds
  var diffDays = Math.abs((dat1.getTime() - dat2.getTime())/(oneDay));
  alert(diffDays);
}

I get the error:

dat1.getTime()` is not a function
  • 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-14T05:01:36+00:00Added an answer on May 14, 2026 at 5:01 am

    That’s because your dat1 and dat2 variables are just strings.

    You should parse them to get a Date object, for that format I always use the following function:

    // parse a date in yyyy-mm-dd format
    function parseDate(input) {
      var parts = input.match(/(\d+)/g);
      // new Date(year, month [, date [, hours[, minutes[, seconds[, ms]]]]])
      return new Date(parts[0], parts[1]-1, parts[2]); // months are 0-based
    }
    

    I use this function because the Date.parse(string) (or new Date(string)) method is implementation dependent, and the yyyy-MM-dd format will work on modern browser but not on IE, so I prefer doing it manually.

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

Sidebar

Related Questions

I am using following code to get bitmap from url. This function is used
Following function is used to get the page's base address of an address which
I used the following to create a modal window: function openAdminModal(dObj, content) { var
I used the following function I found online and it works perfectly. However, when
I know the following function can be used to do some pre-save processing. But,
In the following (working) code example, the templated register_enum() function is used to iterate
I used following JS code to create equal height columns: var colHeight = Math.max($('.3columngallery
I have the following function that is used as the glutKeyboardFunc function parameter: void
hi this is my first attempt at JavaScript: the following function is used to
The following function is defined for all arithmetic types: template <class T> typename enable_if_c<boost::is_arithmetic<T>::value,

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.