-1

I've been trying to use mktime to get which day of the week it is for whatever date I use. But it keeps returning wrong values for wday and yday. I don't care about yday but I'm not sure what the problem. Ive looked over the code multiple times, searched around on the internet etc..., and I've finally run out of ideas of what I could be doing wrong.

Here's a pic of the code and values after calling mktime. If someone could give me a hand I'd appreciate it.

Thanks

enter image description here

Jason White
  • 666
  • 4
  • 10
  • 23
  • `tm_mon` : 0..11, you need `-1` – BLUEPIXY Jan 16 '15 at 10:35
  • 1
    Please don't post code as a picture, this would have taken way less space (both on-screen and in terms of bandwidth) if you had just copy-pasted the relevant lines into the question. – unwind Jan 16 '15 at 10:36
  • Up in arms over a whopping 36kb? The code was posted as a picture to show the debugger values. I don't know how small your screen is but on 1920 * 1080 is displays fine so... – Jason White Jan 16 '15 at 10:58

2 Answers2

4

According to the documentation, the tm_mon field is 0-based, so 1 is actually February.

The tm_mday field is, however, 1-based. It's kind of annoying that they're different.

unwind
  • 391,730
  • 64
  • 469
  • 606
  • 1
    Haha oh God. Ironic since I actually read that too and my brain just completely glossed over that fact. It's always the simple things *sigh* – Jason White Jan 16 '15 at 10:37
0
int tm_mon;         /* month, range 0 to 11             */

The value 1 stands for February needs to be changed to 0.

deimus
  • 9,565
  • 12
  • 63
  • 107
  • 1
    This one liner, which appears to excerpt the header def for the structure could do with more explanation for the OP. I presume you mean that the month is off by 1 because they start at 0 and not 1. Stating this, instead of the pasted code would make the answer more helpful. – Danny Staple Jan 16 '15 at 12:36
  • Thanks for the note @DannyStaple. This is not an excerpt from the definition. Just wanted to have minimalistic answer – deimus Jan 16 '15 at 13:26
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – UmNyobe Jan 16 '15 at 14:45
  • @UmNyobe I've just added some extra info, but where have you seen a link in the answer ? – deimus Jan 16 '15 at 14:49
  • too minimalistic before edit. It is the closest choice I had in the review queue. – UmNyobe Jan 16 '15 at 14:52
  • @UmNyobe Yes it was minimalistic, but just for curiosity, i'm still not getting what do you mean by `link` in the answer ? – deimus Jan 16 '15 at 14:54
  • @UmNyobe ah, got it, sometimes it happens to me too. But just for info, there was and is no any link in the answer ;) – deimus Jan 16 '15 at 14:59