CString convert in Date

Feb 5, 2010 at 5:04pm
Hello Guys ,
I have a CString and it is like [CPLM]......27.12.1999 and I would like to convert date in this String in a DAte form, because I need 27.12.1999 for some calcutaions.
I have just CString inf="23.10.1983";
COleDateTime t; //Test
t.ParseDateTime(inf);
but it did not worked.

If you could help me , I will be very happy
thx,
Feb 5, 2010 at 10:09pm
You're going to have to show more code than that. Post the class definition...
Feb 5, 2010 at 10:14pm
closed account (j3bk4iN6)
in python they have an eval() function that evaluates the string and converts it to integer, is there something similiar in C++
Feb 5, 2010 at 11:13pm
atoi, but it's non-standard (in C++). I think you can use stringstreams for that.
Feb 6, 2010 at 1:59am
POSIX defines strptime() to parse date and time.
Feb 8, 2010 at 8:28am
The Problem ist , I have a string ([CPLM]......27.12.1999), and I want to get 27.12.1999 from this string and I want to convert this 27.12.1999 in data format.
that is the question actually and the for string I used CString ..I am working with MFC

Thank you for your help
Feb 8, 2010 at 9:40am
first use STL algorithm methods like rfind, find, compare...

after that you should get the date like 27121999

then store it in an array, int date[9]; //date[0] = 2, date[1] = 7;

or you can also use modulo

day = 27121999 - 27121999%1000000; for the day.
month = 27121999 - (day*1000000) - 27121999%10000;
year = 27121999%10000;

or simply

date = 27121999;
day = date - date%1000000;
year = date%10000;
month = date - (day*1000000 + year);

use atoi to convert it to int as suggested by chrisname...
Topic archived. No new replies allowed.