Find the month of difference based on the two fixed dates provided

Source: Internet
Author: User
Tags date1

Recently in the calendar, give two days to calculate the difference between the date of this OK, but also to calculate the month a tense did not think out, find on the internet, found, a look, in fact, the method is very simple is not thought

Multiply the year of the date 1 with 12, plus the month of the date 1,

Put the date 2 the same operation

And then subtract two months from the month difference,

Does anyone say that you can do it in a year?

The answer is yes,

Paste Code

The original idea wasn't me.

  

//Two of dates            vardate1 = ' 2016-02-26 '; varDate2 = ' 2015-11-10 '; //Split Month DayDate1 = Date1.split ('-')); //get the number of monthsDate1 = parseint (date1[0]) * + parseint (date1[1]); //Split Month DayDate2 = Date2.split ('-')); //get the number of monthsDate2 = parseint (date2[0]) * + parseint (date2[1]); varm = Math.Abs (Date1-date2); Alert (m);

Did you figure that out, Chung-like,

Find the month of difference based on the two fixed dates provided

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.