Can anyone help me out and tell me how to get Current Date to a CString variable? All I would need is to take the current date in mm/dd/yyyy format, with slashes and all, and put that into a string. Any help would be greatly appreciated.. Thanks...
You can use [tt]CTime::GetCurrentTime()[/tt] to get the current date and time. Then you can use [tt]CTime::Format()[/tt] to format the output into a CString in manner you want!
programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
Perfect! Thanks gednick, was EXACTLY what I needed... One more quick question for you... Is there any way to add up the Day, Month and Year values and put the result into an integer? For Example, 12/17/2002, would equal 12+17+2002=2031. Thanks again for your help on my first question.
Ok, I got it... In case anyone was interested, I just used the GetDay(), GetMonth() and GetYear() functions and assigned them to int values... As easy as that... Thanks again..
well that's good but there's also a couple of other methods it would be handy for you to know about.
First, the basic [tt]time_t[/tt] structure, once intialized, will return the number of seconds that have elapsed since 1970 Jan 1st (I think! if I recall correctly).
Therefore, you can get the current time:
[tt]#include <time.h>
time_t theTime;
time(&theTime);
gmtime(&theTime);[/tt]
if you examine the contents of [tt]theTime[/tt] as a numeric value, it will be a very large integer value. In other words, the number of seconds since 1970.
You can therefore, create a time based on one week from now by adding the appropriate number of seconds to [tt]theTime[/tt] - for example, if you want to create some kind of time limited feature in a program.
However, MFC supplies an easier way called [tt]CTimeSpan[/tt] which includes all the necessary operators for examining and comparing time values.
programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.