probably a dumb date question

Roger Oberholtzer roger
Thu Aug 18 02:23:34 PDT 2005


I need to get the date into a file as text for use in a C program, from
a Makefile. Sounds simple enough:

	#define _MONTH 8

The date command has ways to print various values. However, it seems
that to print the month as a number always has a leading 0. Day of the
month has a format with and a format without the leading 0. But, oddly,
not the month. For August, the date command insists on a leading 0. 
There is no octal 08...

This is the code snippet I am trying:

	echo "#define _MONTH `date "+%m"`"

This will not work as the C interpreter figures 08 is meant to be octal.

I then tried to see if I could get the shell to do this (not interpret
the leading 0 as introducing an octal number):

	let x=`date "+%m"`; echo "#define _MONTH $$x"

Same problem. Not the shell complains in the let statement. It seems
that every program is using scanf() to parse these, so the leading '0'
forces an octal interpretation everywhere. I think that is correct. The
culprit here is the date command, printing invalid numbers!

Is my coffee too weak this morning?

+????????????????????????????+???????????????????????????????+
? Roger Oberholtzer          ?   E-mail: roger at opq.se        ?
? OPQ Systems AB             ?      WWW: http://www.opq.se/  ?
? Kapellgr?nd 7              ?                               ?
? P. O. Box 4205             ?    Phone: Int + 46 8   314223 ?
? 102 65 Stockholm           ?   Mobile: Int + 46 733 621657 ?
? Sweden                     ?      Fax: Int + 46 8   314223 ?
+????????????????????????????+???????????????????????????????+



More information about the Linux-users mailing list