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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:16:55+00:00 2026-05-26T02:16:55+00:00

I am trying to use datejs (date ninja or whathaveyou..) and I am getting

  • 0

I am trying to use datejs (date ninja or whathaveyou..) and I am getting odd results.
Here’s what I output to console to test.

var d1 = Date.today();
var d2 = Date.parse(work.tax_credit_start);
var span2 = new TimeSpan(d2 - d1);

console.log('result of timespan test = ' + span2.getDays() + 'days between now and ' + Date.parse(work.tax_credit_start).toString('dd-mm-yyyy') + ' - ' + work.tax_credit_start );

I am expecting about -584 days according to date calculations in excel and other online services.
Here’s what I got:

result of timespan test = -462days between now and 30-00-2010 - 30-06-2010

I have got a localisation file for datejs for New Zealand style dates too, so I am not expecting that to be an issue. Though it appears to be the issue. Also if I parse a date and then render it as a string in the same format that it was in before being parsed it should not change yeah?

Long day, maybe I just need a break.
Your thoughts/help internets?

  • 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-26T02:16:55+00:00Added an answer on May 26, 2026 at 2:16 am

    Firstly, 30-00-2010 will be resolved as Wed Dec 30 2009 00:00:00. Is that what you really want?

    Secondly, the difference in days between 30-00-2010 and 30-06-2010 is only a couple of days more than 6 months, how do you get -584 days? I get -182.

    Anyway, it’s not a difficult calculation. Create two date objects for the required dates, set their time to noon (so as to remove daylight saving issues across dates), subtract one from the other, divide the result by the number of milliseconds in a day (24 * 60 * 60 * 1000) and round to the nearest integer.

    Here’s a some quick functions to do the job:

    // Iput as d/m/y or d-m-y
    function dmyToDate(s) {
      var bits = s.split(/[-/]/);
      return new Date(bits[2], --bits[1], bits[0]);
    }
    
    
    // Difference between dates in days. If only one date supplied,
    // today is used for endDate
    // Copy startDate so don't mess it up
    function daysBetweenDates(startDate, endDate) {
    
      endDate = typeof endDate == 'string'? dmyToDate(endDate) : new Date();
      startDate = typeof startDate == 'string'? dmyToDate(startDate) : new Date(startDate);
      endDate.setHours(12,0,0);
      startDate.setHours(12,0,0);
    
      var diff = startDate - endDate;
      var ms = 24 * 60 * 60 * 1000; // or 8.64e7
    
      return Math.round(diff/ms);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use Datejs for some date functions. But I am not
I am trying to use the |date filter and running into some problems. Here
I am need paint my image. I'm trying use JQuery in here this link:
trying to use hibernate with my web app and getting following exception: Initial SessionFactory
I'm trying to use timeago ( source ), with datejs , and it's not
I'm trying to use [[NSCalendar currentCalendar] ordinalityOfUnit:NSDayCalendarUnit inUnit:NSEraCalendarUnit forDate:date] on two different dates to
I am trying to use JSON for getting dynamic content to my webpage, using
I been looking at this for far too long here. I'm trying to use
Can you use case expressions in Access? I'm trying to determine the max date
I have been trying to use the step() method on Date object to retrieve

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.