Date and time fuctions in MS Windows is one of the
less trivial things I'm affraid.
But here is a nice approach:
Code:
#include <ctime>
#include <iostream>
using namespace std;
time_t timeDate;
struct tm *currDate;
int main()
{
char yearBuffer[4];
timeDate = time(0);
currDate = localtime(&timeDate); //DOS systemcall!
int month = currDate->tm_mon+1;
int day = currDate->tm_mday;
//int year = currDate->tm_year+1900; //Outputs: 2004
strftime( yearBuffer, 4, "%y", currDate ); //Output: 04 (instead of 2004)
cout<<day<<" "<<month<<" "<<yearBuffer<<endl;
return 0;
} Just a little hint for the upcoming programmer FWIW:
The first thing is clarity. Check out this:
What is this?
Val: 'What is the date today?'
Alex: 'Today is 1'.
Val: 'Huh? What was the date of yesterday or the day before yesterday then?'
Alex: '...'
Do you see what I mean?
GL HF!