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

__DATE__ as ISO string

P: n/a
I want something like content of __DATE__ compiled into my binary.
(Being the date of compilation that is important.) However, I'd like the
compiled-in string to be in the ISO standard format (YYYY-MM-DD) instead
of the default "US" format (Mmm DD YYYY).

Does anyone know a simple, reasonable portable and standard way to
achieve this kind of string being produced at compile-time?

Example:

// I could have:
const char* build_date = __DATE__; // gives "Feb 18 2005" for example
//
// I want:
const char* iso_date = "2005-02-18"; // have to change manually :-(
Any ideas?
-+-Ben-+-
Jul 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Ben Hetland wrote:
I want something like content of __DATE__ compiled into my binary.
(Being the date of compilation that is important.) However, I'd like the
compiled-in string to be in the ISO standard format (YYYY-MM-DD) instead
of the default "US" format (Mmm DD YYYY).

Does anyone know a simple, reasonable portable and standard way to
achieve this kind of string being produced at compile-time?

Example:

// I could have:
const char* build_date = __DATE__; // gives "Feb 18 2005" for example
//
// I want:
const char* iso_date = "2005-02-18"; // have to change manually :-(
Any ideas?


Write a tool that would generate this line _at_the_build_moment_ and put
it into a separate file. Then include that file where you need it.

V
Jul 23 '05 #2

P: n/a
Victor Bazarov wrote:
Write a tool that would generate this line _at_the_build_moment_ and put
it into a separate file. Then include that file where you need it.


Yes, fair enough, but I'd rather not rely on any extra tool in this
case, because this is part of a library/include set and is used by
numerous projects already. (It would require me to change the build
process of all projects that happen to use it, and also have a tool
built/installed for each platform & computer.)

BTW, I also need it to work for debug builds where optimization is
disabled. Other than this I was kinda hoping there's a "clever" macro or
template trick that can have the compiler do this directly... ;-) But
perhaps enabling optimization just for this code section can be forced
anyway if that can help the compiler emit the right bits.
-+-Ben-+-
Jul 23 '05 #3

P: n/a
Ben Hetland wrote:
Victor Bazarov wrote:
Write a tool that would generate this line _at_the_build_moment_ and put
it into a separate file. Then include that file where you need it.

Yes, fair enough, but I'd rather not rely on any extra tool in this
case, because this is part of a library/include set and is used by
numerous projects already. (It would require me to change the build
process of all projects that happen to use it, and also have a tool
built/installed for each platform & computer.)

BTW, I also need it to work for debug builds where optimization is
disabled. Other than this I was kinda hoping there's a "clever" macro or
template trick that can have the compiler do this directly... ;-) But
perhaps enabling optimization just for this code section can be forced
anyway if that can help the compiler emit the right bits.


I honestly think you're better off with a tool simply because there isn't
any mechanism in the C preprocessor to manipulate strings. If you find
a setting or a macro in your compiler that allows you to get a different
format of the compilation date, it's likely not to be portable. OTOH, if
you don't care about being portable, talk to the compiler maker to see if
they are willing to accommodate your request and implement it into their
next release.

V
Jul 23 '05 #4

P: n/a
Ben Hetland wrote:
// I could have:
const char* build_date = __DATE__; // gives "Feb 18 2005" for example
//
// I want:
const char* iso_date = "2005-02-18"; // have to change manually :-(


Why don't you parse the __DATE__ at runtime?

Greetings,
Johannes

--
PLEASE verify my signature. Some forging troll is claiming to be me.
My GPG key id is 0xCC727E2E (dated 2004-11-03). You can get it from
wwwkeys.pgp.net or random.sks.keyserver.penguin.de.
Also: Messages from "Comcast Online" are ALWAYS forged.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCF0KXCseFG8xyfi4RAvJeAJ9BKeOcYWqOU/joiUTpB/a4SpYnVgCgg2I9
WkhjQX0AHW18iDdVv2WMnLQ=
=b3Q0
-----END PGP SIGNATURE-----

Jul 23 '05 #5

P: n/a
Johannes Bauer wrote:
Why don't you parse the __DATE__ at runtime?


Because I want it compiled into the executable, for potential version
tracking.

--
Regards,
-+-Ben-+-
Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.