The day of the year function does not seem to work in Device Code on an Imp 001, 002, 003 boards

Purchased an Imp 003 from Mouser and have moved working code onto it from an April Board. In the code, I calculate the month, day, year, weekday and day of the year using the date() function. The code works on the agent side of April, Amber, and Imp 003 boards (on your servers), however, on the device side of all three boards, the calculation of yday always yields 0. The other date() values seem to be correct.

The code is below:
local currentTime = date(time(), 'u');
local currenthour = currentTime.hour ;
local currentmin = currentTime.min ;
local currentday =;
local currentwday = currentTime.wday
local currentmonth = currentTime.month + 1;
local currentyear = currentTime.year;
local dayofyear = currentTime.yday;

server.log(format("Device: Day of Year (%u, %u)", dayofyear, currentTime.yday ) );

I have tried using:
local currentTime = date();

But it doesn't affect the day of the year value.

Any thoughts?


  • This a known regression in release 34 (was reported recently by another customer), and will be addressed in the next release.

    Should be possible to work around it for now using the year (to determine leap year) and month/day entries - let us know if you want an example.
  • Thanks. Already have code in place that does leap year calculations and an array with the number of days in each month so I will use that code. When will next release be deployed?
  • Release 36 - which includes various other new features (eg background wifi scanning, local config page storage on all imps, official imp004m support and imp005 improvements like wifi-only and ethernet-only modes) is due to go into beta sometime next month.
Sign In or Register to comment.