PDA

View Full Version : Date to day of the year functionality



Ruditec
06-07-2011, 08:43 AM
Does anyone know of a .pm or .cm that provides the functionality of converting date into day of the year. i.e. 1st January = day 1 and 31st December = day 365 (366 in a leap year)

Paul Green
06-16-2011, 06:58 PM
You can obtain the day of the year from the C "gmtime" or "localtime" function. These functions take a clock value and return the broken-down time in the "tm" structure. The "tm_yday" element of this structure holds the zero-origin value of the day of the year. The gmtime function returns the information for the UT (GMT) time zone; the localtime function takes your current time zone into account.

Alternatively, you can also take the current time modulo the number of seconds in a year, divide by the number of seconds in a day, and find the zero-origin value of the day of the year. Since VOS returns the current time in UT (GMT), you would, of course, need to adjust for the difference between your local time zone and UT (GMT).

Hope this helps.
PG

Ruditec
06-24-2011, 09:31 AM
That's very useful. Thanks Paul.