string to DATE

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This question continues on from a previous post "DATE to string" but I think
it deserves a new thread.

In my previous post I was trying to convert a DATE to string in a NON MFC
C++ application which (with a little help) was achieved with the following
code:

******************
// Variables
DATE MailDateTime;

LPSYSTEMTIME SysTime;

string FormattedDateTime;

std::ostringstream oss_date;



//Get mail received time from outlook to DATE
MailDateTime = spMailItem->GetReceivedTime();

//Convert DATE to LPSYSTEMTIME
VariantTimeToSystemTime(MailDateTime, SysTime);

//Build string stream from date parts for readable format day/month/year
oss_date << SysTime->wDay << "/" << SysTime->wMonth << "/" << SysTime->wYear;

//assign string stream to string
FormattedDateTime.assign(oss_date.str());

*******************

I now need to go the other way which again I am having trouble with..

Firstly I need to get a string containing a formatted date time (e.g
"25/10/2006 10:15:00") into a LPSYSTEMTIME and then convert to a DATE type
using SystemTimeToVariantTime.

The main issue I am having at the mo is the conversion from string to
LPSYSTEMTIME.

Can anyone help with this?

Thanks again...
 
jwf said:
This question continues on from a previous post "DATE to string" but I think
it deserves a new thread.

In my previous post I was trying to convert a DATE to string in a NON MFC
C++ application which (with a little help) was achieved with the following
code:

******************
// Variables
DATE MailDateTime;

LPSYSTEMTIME SysTime;

string FormattedDateTime;

std::ostringstream oss_date;



//Get mail received time from outlook to DATE
MailDateTime = spMailItem->GetReceivedTime();

//Convert DATE to LPSYSTEMTIME
VariantTimeToSystemTime(MailDateTime, SysTime);

//Build string stream from date parts for readable format day/month/year
oss_date << SysTime->wDay << "/" << SysTime->wMonth << "/" << SysTime->wYear;

//assign string stream to string
FormattedDateTime.assign(oss_date.str());

*******************

I now need to go the other way which again I am having trouble with..

Firstly I need to get a string containing a formatted date time (e.g
"25/10/2006 10:15:00") into a LPSYSTEMTIME and then convert to a DATE type
using SystemTimeToVariantTime.

The main issue I am having at the mo is the conversion from string to
LPSYSTEMTIME.

Can anyone help with this?

Thanks again...

I have figured out the problem. To do this was fairly simple as expected..
The issue I was having was due to a memory allocation issue pointed out in my
"DATE to string" post and causing the application to crash.

Please see the "DATE to string" thread for further info.
 
Back
Top