Link to home
Start Free TrialLog in
Avatar of bobby101
bobby101

asked on

User input date

i want a user to enter a date than get the week number so far i know how to get the week number by using strftime(date,3,"%W",&date) but dont know how to pass it into date
Avatar of Infinity08
Infinity08
Flag of Belgium image

strftime needs a struct tm :

        http://www.cplusplus.com/reference/clibrary/ctime/tm/

So, you'll need to fill such a struct with the data you get from the user. Once you have that, you can pass it to strftime.
Avatar of bobby101
bobby101

ASKER

i have been playing around with it but its not doing what i was please help


int week;
 char date[3];
 int year, month ,day;
 struct tm timei;
cout <<"dd-MM-yyyy";
 cin>> day >> month >> year;

 timei.tm_yday = day;
 timei.tm_mon = month-1;
 timei.tm_year += year-1900;

 strftime(date,3,"%W",&timei);
 week = atoi(date);
 cout << week;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial