473,395 Members | 1,484 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Date conversions in C or C++

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
1 1668
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
7
by: Mick White | last post by:
According to the Safari browser the world began on "Fri Dec 13 1901 15:45:52 GMT-0500", but I need to be able to get around this limitation. I am interested in dates from 1500 to 1901, as far as...
12
by: DC Gringo | last post by:
How can I convert this pubLatest to a date with format "m/d/yyyy"? Dim pubLatest As New Date pubLatest = Me.SqlSelectCommand1.Parameters("@pubLatest").Value -- _____ DC G
8
by: John Wildes | last post by:
Hello all I'm going to try and be brief with my question, please tell me if I have the wrong group. We are querying transaction data from a DB3 database application. The dates are stored as...
26
by: jshanman | last post by:
I am writing a timeline that uses Google Maps. I have a function that converts a date time to latitude coords. This function is used to draw the markers on the timeline. I need a reverse function...
4
by: blini | last post by:
Helo.... How I can convert string "26/03/2006 15:51" for a date? I need to convert and to compare if "09/06/2006 14:20" is lesser or equal that the current date. Everything in Javascript.
7
by: Richiep | last post by:
I am trying to get a UK format date of dd/mm/yyyy. Why does the following subroutine not return a valid date in a web form? The date returned is #12:00:00 AM# but the date I entered into the...
9
by: Bob Sanderson | last post by:
I have a field in a database called DateRcvd. At present, it outputs in my report in the yyyy-mm-dd format. I would like it to display in the dd/mm/yy format. What is the easiest way to accomplish...
10
by: DontellTrevell via AccessMonster.com | last post by:
HELP!!....I need to calculate the numer of days elapsed between two field. But, the date format is YYYYMMDD. How can i accomplsh this? -- Dontell Trevell Message posted via AccessMonster.com...
6
by: Jeremy Sanders | last post by:
Hi - I need to add support to a program for dates and times. The built-in Python library seems to be okay for many purposes, but what I would like would be Unix epoch style times (seconds relative...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.