By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,208 Members | 1,592 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,208 IT Pros & Developers. It's quick & easy.

Date conversions in C or C++

P: n/a
Hi All,
I promise I did my homework and looked around, but I can't find a
simple date/datetime converter in C or C++. I think there might be one
in YACL and things like that but it's pretty huge and I was hoping to
find just a simple snippet somewhere.

Situation is I have some files with varying date/date time formats in
them. They are coming in as strings. I am setting some parameters to
my code to tell it what format the date/datetime is in for this file.
(only one format each per file) And from the definition of the format I
want to convert each date/datetime field to it's ISO format YYYY-MM-DD
and YYYY-MM-DD HH:MM:SS.MMM.

I am guessing that such a snippet exists as this is an extremely common
activity. I am surprised I didn't find one searching.

I'm looking for C or C++. C would be nice and easy as my code is C++
but where I want to put this is inside another class where I already
have the format defintion and the date field to convert as C strings.

Any pointer would be most appreciated..

Best Regards
Peter Nolan
www.peternolan.com

Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Peter Nolan wrote:

Hi All,
I promise I did my homework and looked around, but I can't find a
simple date/datetime converter in C or C++. I think there might be one
in YACL and things like that but it's pretty huge and I was hoping to
find just a simple snippet somewhere.

Situation is I have some files with varying date/date time formats in
them. They are coming in as strings. I am setting some parameters to
my code to tell it what format the date/datetime is in for this file.
(only one format each per file) And from the definition of the format I
want to convert each date/datetime field to it's ISO format YYYY-MM-DD
and YYYY-MM-DD HH:MM:SS.MMM.

I am guessing that such a snippet exists as this is an extremely common
activity. I am surprised I didn't find one searching.


Maybe it is not *that* common :-)

Anyway:
What you need is some code which does the parsing of existing date/datetime
strings (if the format is fixed and you are sure that no high sophisticated
error handling needs to be done eg. a simple sscanf() can do the job).
When you have that you can easily fill in the values in a 'struct tm'
and use function strftime() to format it according to your needs.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.