Jump to content
Larry Ullman's Book Forums

Ctime - Handling Dates As Far Back As Imaginable

Recommended Posts


I'm wondering about the limitations of ctime and mktime.

For example:

time_t t;

struct tm * timeinfo;

string weekday[] = { "Sunday", "Monday",

"Tuesday", "Wednesday",

"Thursday", "Friday", "Saturday"};

// get current timeinfo and modify it to user's choice

t = time(NULL);

timeinfo = localtime(&t);

timeinfo->tm_year = local_year - 1900;

timeinfo->tm_mon = local_month - 1;

timeinfo->tm_mday = local_day;


// call mktime: timeinfo->tm_wday will be set



cout << "That day is a " << weekday[timeinfo->tm_wday] << endl;


I am trying to determine the day of ANY date. Ideally, I would like it to be able to handle dates as far back as 5000 BC (if that is even possible) or year -5000....if not then maybe atleast 100 AD........


Am I asking C++ to do something it can't handle any more?

How do I do what I described above in C++?

What's the earliest date that ctime can handle? Is it only from 1970???


Thank you

Link to comment
Share on other sites

This is very tricky. You'll have to check online for the details, but around 1100, 10 days were added to the calendar and we switched from Julian to Gregorian calendars (or vice versa). And I don't know when leap days were introduced. It would kind of surprise me if there isn't a C++ library that handles this (to some degree) already.

Link to comment
Share on other sites

  • 2 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...