PDA

Click to See Complete Forum and Search --> : convert string to date


wey97
Nov 5th, 2000, 01:11 AM
In C++, does anyone know how to convert a string to a date, or extract integers representing the date? My string would be something like:


string sdate = "01012000";


I want to extract 1, 1, 2000 into three separate ints.

[Edited by wey97 on 11-08-2000 at 04:42 PM]

wey97
Nov 5th, 2000, 01:50 AM
OK, I figured it out myself:


string sdate = "01012000";
int month, day, year;

month = 10*int(sdate[0]-'0') + int(sdate[1]-'0');
day = 10*int(sdate[2]-'0') + int(sdate[3]-'0');
year = 1000*int(sdate[4]-'0') + 100*int(sdate[5]-'0') + 10*int(sdate[6]-'0')+ int(sdate[7]-'0');