Menu
Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
Convert __DATE__ to unsigned int
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Erik Cato" data-source="post: 1692169"><p>Hi group!</p><p></p><p>Anyone know a way to convert the __DATE__ predefined macro into a</p><p>unsigned int representing the current date? It should </p><p>be possible to make out what date it was from the beginning.</p><p>My idéa was this format: ((Year - 2000)*12 + (month - 1))*31 + day</p><p>So 12 Dec 2003 would result in: ((2003 - 2000)*12 + (12 - 1))*31 + 12 = 1469</p><p></p><p><OT></p><p>What im trying to accomplish is to display a number representing </p><p>the build date of the code in a 4-digit 7-segment display.</p><p></OT></p><p></p><p>Preferbly i would have a solution that does it at compile time?</p><p></p><p>Something like this:</p><p></p><p>#define DATE_AS_INT /* something nice here */</p><p></p><p>displayAsInt(DATE_AS_INT);</p><p></p><p>The next best thing is a function returning the int. But i cannot use </p><p>any library functions.</p><p></p><p>Like this</p><p></p><p>unsigned int getDateAsInt()</p><p>{</p><p> /* Code goes here */</p><p>}</p><p></p><p>displayAsInt(getDateAsInt());</p><p></p><p>The reason for the somewhat strange constraints is that im developing for</p><p>an embedded system and im having a little short on code memory. </p><p></p><p>Greatful for any suggestion!</p><p></p><p>//Erik</p></blockquote><p></p>
[QUOTE="Erik Cato, post: 1692169"] 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 idéa was this format: ((Year - 2000)*12 + (month - 1))*31 + day So 12 Dec 2003 would result in: ((2003 - 2000)*12 + (12 - 1))*31 + 12 = 1469 <OT> What im trying to accomplish is to display a number representing the build date of the code in a 4-digit 7-segment display. </OT> Preferbly i would have a solution that does it at compile time? Something like this: #define DATE_AS_INT /* something nice here */ displayAsInt(DATE_AS_INT); The next best thing is a function returning the int. But i cannot use any library functions. Like this unsigned int getDateAsInt() { /* Code goes here */ } displayAsInt(getDateAsInt()); The reason for the somewhat strange constraints is that im developing for an embedded system and im having a little short on code memory. Greatful for any suggestion! //Erik [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
Convert __DATE__ to unsigned int
Top