Hello
I am making a function that takes in a date (dd/mm/yy) & returns what week number of the year the date occurs on.
For eg;
If I enter: 01/01/09 then the week number of that year will be 1
If I enter: 04/09/09 then the week number of that year will be 35
I have this function I altered that gives the week number of the current date ONLY.
Is there a way to alter the below function where it takes in a parameter of a date(dd/mm/yy) & returns what number week that is of the year??
Ie, alter this function to take in a given date & return what week number that would be.
I hope that makes sense :P
void getWeek(int& week) {
time_t rawtime;
struct tm * timeinfo;
char buffer[4];
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (buffer,4,"%W",timeinfo); // '%W' = week number of the year, eg 1/1/09 == 1
week = atoi(buffer); // convert char to int
}
for example
void getWeek(string& date) { // date format 'dd/mm/yy'
time_t rawtime;
struct tm * timeinfo;
char buffer[4];
string d = date[0] + date[1];
string m = date[3] + date[4];
string y = date[6] + date[7];
time ( &rawtime );
timeinfo = date; // is that correct????
strftime (buffer,4,"%W",timeinfo); // '%W' = week number of the year, eg 1/1/09 == 1
week = atoi(buffer); // convert char to int
}