The number of days between two dates -- [programming Pearl]

Source: Internet
Author: User

Attacked by various csdn bulls... continue to cheer...

Today I flipped through "programming Pearl River". In fact, this book is still a bit deep to myself and cannot be eaten.

A small question isCalculate the number of days in the two days;

It happens that the same problem occurs when you do web jobs a few days ago. However, if you call system functions directly for that question, the two dates minus/1000/60/60/24 is the number of days;

In c, I really don't know if there are such powerful functions. If so, let me know;

Let's talk about what I implemented. I gave two dates, respectively, to find the number of days that have elapsed since the first year of the current year, and then subtract from each other, that is, the number of days of the difference (both positive and negative, everyone understands );

/*********** 2013-12-30 * _ Luffy * http://blog.csdn.net/xjm199?##########/#include
 
  
Int isleapyear (int year) // whether it is a leap year {return (year % 4 = 0 & year % 100! = 0) | year % 400 = 0);} int sum (int year, int month, int day) {int mon [] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int sum = (year-1) * 365; // Number of days since the first year of the current year int I; sum + = (year-1)/4 + 1; // sum-= (year-1)/100 + 1 can be added to all the four divisible items; // The sum + = (year-1) of the 100 divisible items is not the sum + = (year-1) of the leap year) /400 + 1; // The Real divisible by 400 is the leap year for (I = 0; I <month-1; ++ I) // Add sum + = mon [I] to the remaining month of the current year; if (isleapyear (year) = 1 & month> 2) // do you want to renew this year on April 9, February + sum; sum + = day; // Add return sum on the day of this month;} int main () {printf ("% d \ n ", sum (2013, 11, 1)-sum (2013, 9, 30); return 0 ;}
 

Sum is the day since the first year of the year;

The result is as follows:

32Process returned 0 (0x0)   execution time : 0.331 sPress any key to continue.


Welcome to mention... o (∩ _ ∩) o
 

Related Article

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.