Several times now in different jobs, I have come across the need for a better __DATE__ and __TIME__, and always had to use a function such as that listed below.
This is probably a question for the steering committee, but can I suggest the following. In particular, some formats which are sortable in a directory listing or table, and some of which can be used as part of a valid file name (eg, for Windows and Linux file systems). I suggest the following 4 macros: Macro: Expands to: __YYYY_MM_DD__ 2007-02-20 also know as 'Swedish format' __YYYYMMDD__ 20070220 as above, but no delimiters, for a file name part __HH_MM_SS__ 15:51:52 24-hour format __HHMMSS__ 155152 as above, but no delimiters, for a file name part Typical function to get a combined Swedish format date and time from the build __DATE__ and __TIME__: /*! \file swedish_build.c \author (c) 2004-2007 Alf Lacis. \brief Converts the 'standard' __DATE__ and __TIME__ macros into a useful Swedish-formatted string of the form "YYYYMMDD.HHMMSS". \date 20040615 AGL Created from yyyymmdd.c. ***************************************************************************************************/ #include <string.h> #include <ctype.h> #include "alflb.h" // for prototypes, etc const char *mmm[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; const char *mm[] = { "01" , "02" , "03" , "04" , "05" , "06" , "07" , "08" , "09" , "10" , "11" , "12" }; // 012345678901234.... // Converts __DATE__ string: "Feb 5 2007" // And __TIME__ string: "09:42:12" // to Swedish format: "20070205.094212" char *swedish_build( char swedish[], size_t sizeof_swedish, char yankee_date[], char yankee_time[] ) { int ii; if ( sizeof_swedish < SWEDISH_BUILD_SIZE ) { return NULL; } strcpy( swedish, " . " ); // 8 spaces, dot, 6 spaces, 1 trailing '\0' memcpy( swedish, &yankee_date[7], 4 ); for ( ii = 0; ii < 12; ii++ ) { if ( strncmp( yankee_date, mmm[ii], 3 ) == 0 ) { memcpy( &swedish[4], mm[ii], 2 ); break; } } memcpy( &swedish[6], &yankee_date[4], 2 ); memcpy( &swedish[9] , yankee_time, 2 ); memcpy( &swedish[11], &yankee_time[3], 2 ); memcpy( &swedish[13], &yankee_time[6], 2 ); replace( swedish, ' ', '0' ); return swedish; } // end of file: swedish_build.c -- Summary: Can we have a new __DATE__ which is sortable, eg YYYY- MM-DD Product: gcc Version: 3.4.2 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: preprocessor AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: alf dot lacis at aiscientific dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30867