473,395 Members | 1,343 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__ as ISO string

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

Similar topics

16
by: Krakatioison | last post by:
My sites navigation is like this: http://www.newsbackup.com/index.php?n=000000000040900000 , depending on the variable "n" (which is always a number), it will take me anywhere on the site......
5
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
9
by: John F Dutcher | last post by:
I use code like the following to retrieve fields from a form: recd = recd.append(string.ljust(form.getfirst("lname",' '),15)) recd.append(string.ljust(form.getfirst("fname",' '),15)) etc.,...
9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
7
by: Erik Cato | last post by:
Hi group! Anyone know a way to convert the __DATE__ predefined macro into a unsigned int representing the current date? It should be possible to make out what date it was from the beginning. My...
2
by: Christopher Benson-Manica | last post by:
Recently a great example of converting __DATE__ into an integer via preprocessor tricks was posted. I've been trying to accomplish something similar - convert __DATE__ into a string in the format...
2
by: Jeffrey Bradshaw | last post by:
Are there compile date/time and file line equivalents for __DATE__ and __FILE__ in C#?
1
by: Sagaert Johan | last post by:
Hi Are there any predefined constants i could use in my C# code similar to __DATE__ __FILE__ __LINE__ in c++ ? Johan
1
by: Zero | last post by:
Hello all, is it possible to change the format of __FILE__ + __DATE__, for example instead of hh:mm:ss ss:mm:hh? Where can I get information on this topic?
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:
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.