DATE in string

Let say I have a string which is 2011-2-3 , how do I convert it into days in 365 in 2011? How do I use find function and substr function in this case?
assuming that the string is constant, and you're using ctime
http://www.cplusplus.com/reference/clibrary/ctime/ctime/

The returned string has the following format:

Www Mmm dd hh:mm:ss yyyy
Where Www is the weekday, Mmm the month in letters, dd the day of the month, hh:mm:ss the time, and yyyy the year.

output is a string, so basically you access the Mmm, dd and yyyy char, and manipulate them.

with the month, use a series of if-else/switch statements to tell the number of days. for example, if the month is jan, mar or may, then day=31

with the days, take the first digit, change to int (using arithmetic or functions), multiply by 10, then add with the second digit. for example, if its the 21st, we take in '2', change to int, multiply by 10 to get 20. then we add up the second digit, 1 to get 21. note that the output is string, so its in an array of characters.

well, thats just my way. possible for other simpler solutions. hope this helps :D
Topic archived. No new replies allowed.