C
Christopher Benson-Manica
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
YYYYMMDD. MONTH is easy - replace the numbers with strings and voila.
YEAR is also easy - __DATE__ + 7 works nicely. DAY, however, has me
stumped. There's got to be something better than
#define DAY ((__DATE__[4] == ' ' ? \
__DATE__[5] == '1' ? "01" : \
__DATE__[5] == '2' ? "02" : \
...
: __DATE__[4] == '1' ? ...
Right?
preprocessor tricks was posted. I've been trying to accomplish
something similar - convert __DATE__ into a string in the format
YYYYMMDD. MONTH is easy - replace the numbers with strings and voila.
YEAR is also easy - __DATE__ + 7 works nicely. DAY, however, has me
stumped. There's got to be something better than
#define DAY ((__DATE__[4] == ' ' ? \
__DATE__[5] == '1' ? "01" : \
__DATE__[5] == '2' ? "02" : \
...
: __DATE__[4] == '1' ? ...
Right?