I'm trying to find out the week number of a date in C++. I'm taking my date from the console as a string and dividing it into the date, month, and year.
This is my code. Please help me to find out the problem.
#include <iostream>
using namespace std;
#include <string>
#include <cstring>
#include <ctime>
int main(void)
{
struct tm tm;
char timebuf[64];
memset(&tm, 0, sizeof tm);
string date;
cout<<"Enter the date (dd-mm-yyyy) : "; //print statement is used to print message on console
cin>>date; //taking input from user
int day=stoi(date.substr(0,2));
int month=stoi(date.substr(3,2));
int year=stoi(date.substr(6,4));
//cout << day << month << year << endl;
tm.tm_sec = 0;
tm.tm_min = 0;
tm.tm_hour = 23;
tm.tm_mday = day;
tm.tm_mon = month;
tm.tm_year = year;
tm.tm_isdst = -1;
mktime(&tm);
if (strftime(timebuf, sizeof timebuf, "%W", &tm) != 0) {
printf("Week number is: %s\n", timebuf);
}
return 0;
}