LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

First weekday in mont and week number

I need a function to determine which weekday is the first in (any) month, how many days in that month and whitch week numbers accosiated.

Anyone with a good idea ?

0 Kudos
Message 1 of 4
(4,852 Views)

You can use one of my contributions to get the week number given a date.

In that code you can get also an idea as to how to calculate the lenght of february given the year with the appropriate leap year adjustment.

 

You can get the day of week by calling mktime () function: fill in the date fields and pass the struct to the function that will calculate and update the struct for the day of the week.

 

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 4
(4,851 Views)

Hi Roberto

I'm using another of your contribution.

http://forums.ni.com/t5/LabWindows-CVI/ISO-week-number/m-p/119010/highlight/true#M9735

 

If I could get the day of week also it would be good enough. I does not seem that tm_wday gets update with mktime()

The input to the modified function is day,month,year (day 1-31, month 1-12) . The week is calculated but I need the day of week .

0 Kudos
Message 3 of 4
(4,834 Views)

On my machine mktime is working correctly.

This code can be pasted and executed in the Interactive Execution window: does it return any error? Code queries for today and should return day #1 of week, that is monday.

 

 

#include <utility.h>
#include <ansi_c.h>
#include <time.h>

static time_t		k;
static struct  tm	y;

memset (&y, 0, sizeof (struct tm));
y.tm_mday = 6;
y.tm_mon = 9;
y.tm_year = 114;
y.tm_hour = 9;
k = mktime (&y);
if (k == -1)
	DebugPrintf ("Error in mktime function\n");
else {
	DebugPrintf ("Day of week; %d\n", y.tm_wday);
	DebugPrintf ("Daylight savings time: ");
	if (y.tm_isdst > 0)
		DebugPrintf ("Effective\n");
	else if (!y.tm_isdst)
		DebugPrintf ("Not effective\n");
	else
		DebugPrintf ("Unknown\n");
}

 

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 4
(4,793 Views)