Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Converting a COleDateTime to and from a string

Posted on 2004-03-25
4
Medium Priority
?
3,313 Views
Last Modified: 2011-09-20
Hello experts

I have a string that I download from a database which holds a date
1039046400000 (the number of seconds from 1970)
I want to convert this string to a COleDateTime variable
After I do some work on the COleDateTime variable I want to convert it back in to a string ( the number of seconds from 1970 ).


My question is
How do I convert COleDateTime object to and from a string which contains the number of sec since 1970 ?

thank you for your time
0
Comment
Question by:funvill
  • 2
4 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 10682897
1. COleDateTime --> string

COleDateTime::Format()

2. string --> COleDateTime

COleDateTime::ParseDateTime()
0
 
LVL 8

Accepted Solution

by:
mnashadka earned 200 total points
ID: 10682993
To get the COleDateTime, you would say:
time_t seconds = atoi("1039046400000");
COleDateTime date(seconds);

To get it back in that format:
time_t seconds = (date - COleDateTime(1970, 1, 1, 0, 0, 0)).GetTotalSeconds();
Then just do a sprintf or ostringstream or whatever to get that as a string.  Good luck.
0
 
LVL 23

Expert Comment

by:chensu
ID: 10683003
Oops... I didn't read the question carefully.
0
 
LVL 2

Author Comment

by:funvill
ID: 10683089
Thank you mnashadka
it works great
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question