weekday keyword in time lib

Hi All,
I am wanting to get the weekday from my 1307 module. I can get all the other data like hour Minute etc.
but can't find a keyword that will work. I am using the Margiolis lib and the notes show the keywords thus:-
#######################################

Syntax Coloring Map For Time

#######################################

#######################################

Datatypes (KEYWORD1)

#######################################
time_t KEYWORD1
#######################################

Methods and Functions (KEYWORD2)

#######################################
now KEYWORD2
second KEYWORD2
minute KEYWORD2
hour KEYWORD2
day KEYWORD2
month KEYWORD2
year KEYWORD2
isAM KEYWORD2
isPM KEYWORD2
weekday KEYWORD2
setTime KEYWORD2
adjustTime KEYWORD2
setSyncProvider KEYWORD2
setSyncInterval KEYWORD2
timeStatus KEYWORD2
TimeLib KEYWORD2
#######################################

Instances (KEYWORD2)

#######################################

#######################################

Constants (LITERAL1)

#######################################
I've tried various combinations of weekday but it won't compile, comes up with
'struct tmElements_t' has no member named 'weekday'.
When I type in "weekday"it comes up in the red text as other keywords.

This is the line that trips the error.

Serial.println(tm.weekday);

Any help appreciated :_)

What about weekday() ?

If I'm looking at the corrrect library, you should be able to print the text for the day of the week from dayStr(weekday()) or dayShortStr(weekday()) .

tm.Wday would be the numeric day of the week, starting with Sunday as 1

Thanks David and UKHeliBob,

Using UKHeliBob's suggestion sorted it out, I was having trouble with the weekday using the case function to print the day of week.
Cheers ........ Blakus

I was having trouble with the weekday using the case function to print the day of week.

If you mean that you are using switch/case to print the text of the day of the week, that is a clumsy way to do it

Hi All,
I am using the line " switch(weekday()){" to get the weekday but it is not updating, ie. it returns the digit 5 all the time. I can't think of what is wrong, the date and time are updating OK but not the weekday.

Anyone ??

Cheers ...... Blakus

Link to your library? What hardware?

(If you had an existing post on that topic, why did you create a new one?)

Topics merged

J-M-L:
Link to your library? What hardware?

(If you had an existing post on that topic, why did you create a new one?)
[/quote

So I'm new to it, cut me some slack we all have to start somewhere :confused:

Im using the time.lib by margeolis on an 1280 clone.

UKHeliBob:
If you mean that you are using switch/case to print the text of the day of the week, that is a clumsy way to do it

Ah well that came from an example on the site, what's a better way then ?

what's a better way then ?

Put the names in an array and use the day of the week variable as an index

char * dayNames[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  for (int day = 0; day < 7; day++)
  {
    Serial.println(dayNames[day]);
  }
}

void loop()
{
}

Note that you need to adjust the array to match the day on which the week starts

Thanks to both of you, I've learnt heaps from the exercise. I guess that's the usual path to learning :slight_smile: