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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:03:27+00:00 2026-06-02T17:03:27+00:00

#include <time.h> #include <iostream> int main() { struct tm dayofmonth = {0}; int iYear

  • 0
#include <time.h>
#include <iostream>
int main()
{

        struct tm dayofmonth = {0};
        int iYear = 2012;
        int iMonth = 2; // February

        dayofmonth.tm_year = iYear - 1900;
        dayofmonth.tm_mon =  iMonth;
        dayofmonth.tm_mday = 0;
        dayofmonth.tm_isdst = 0;

        mktime(&dayofmonth);

        std::cout << "Number of days for the month " << dayofmonth.tm_mon << " is " << dayofmonth.tm_mday << std::endl;

}

Needed to write a simple routine, to find the number of days for a given month. However, for mktime, why should I pass the actual month number instead of month number -1.

It is more confusing, that after calling mktime, the tm_mon returns month -1 instead of the original month that was passed.

  • 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-06-02T17:03:28+00:00Added an answer on June 2, 2026 at 5:03 pm

    Because you set tm_mday = 0. The “zeroth” of the month (tm_mon = 2 means March) rolls back to the last day of the previous month (February).

    Yes, it is confusing that tm_mday is 1-based whereas tm_mon is 0-based. You get used to it eventually 🙂

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

Sidebar

Related Questions

Consider this code: #include <iostream> template<class C> struct time { }; int main() {
#include<iostream> #include<time.h> #include<list> #include<stdlib.h> #include<fstream> using namespace std; typedef struct diskBtNode { int parent;
My code is the following: #include <iostream> #include <sys/time.h> using namespace std; int main(int
#include <ctime> #include <iostream> #include <cstring> int main() { struct tm tm ; //memset(&tm,
Consider the following code which shows compile time error : #include <stdio.h> int main(int
#include<stdio.h> #include<time.h> int main() { clock_t start; double d; long int n,i,j; scanf(%ld,&n); n=100000;
I have the following code: #include <iostream> using namespace std; struct stud{ int roll;
#include <iostream> int main() { const std::string exclam = !; const std::string message =
Please see the code below: #include <iostream> #include <stdlib.h> #include <time.h> using namespace std;
Well, not random, because its the same every time, but #include<iostream> using namespace std;

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.