LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

get day

Hi,

I'm using CVI 6.0 and WIN XP PRO SP2.

I need to get the day of the WEEK, I've used the MSCAL (Active X calendar) but MSCAL will not tell me if I'm monday...or any other day of the week. I took a look in the CVI library and even in the DATE/TIME library nothing will tell me the day of the WEEK. So is there a method to find out the current day of the WEEK wich is a value 1-7 ?

Thank you,
0 Kudos
Message 1 of 6
(4,252 Views)
Hi,

You can use 'InternationalDate' function from the Programmer's tool box to get the information of current day.
I do not think we have direct functions in CVI to know about the information of any date.You can develop a program in LabVIEW using the Date/Time functions which do that and call the dll in CVI.

Regards,
Siddu
0 Kudos
Message 2 of 6
(4,240 Views)

This should work if you have the year, month and day:

#include <time.h> // struct tm, etc are defined here

void GetDay(void)
{
// Set up a variable of type struct tm and a pointer to it
struct tm ts, *t=&ts;
// this will contain the calendar date in seconds
time_t ct;
// local variables
int year, month, day, weekday;

// Example: 16 December 2004
Year = 2004 - 1900; // years since 1900
Month = 11; // January = 0, February = 1, etc
Day = 16; // The first day of the month is 1 (not 0)

// Zero out the tm structure
memset (t, 0, sizeof(struct tm));
// Set the year, month and day
t->tm_year = year;
t->tm_mon = month;
t->tm_mday = day;
// Get the calendar time
ct = mktime(t);
// Convert to component parts
t = gmtime(&ct);
// Add 1 to weekday for a value of 1 to 7
weekday = t->tm_wday + 1;
// weekday contains the day of the week
// 1 = Sunday through 7 = Saturday
}

If you want the current day use the function DateStr().

Regards,
George Hodgson

"gasma1975" <x@no.email> wrote in message news:169698@exchange.ni.com...
> Hi,<br><br>I'm using CVI 6.0 and WIN XP PRO SP2.<br><br>I need to get the
day of the WEEK, I've used the MSCAL (Active X calendar) but MSCAL will not
tell me if I'm monday...or any other day of the week. I took a look in the
CVI library and even in the DATE/TIME library nothing will tell me the day
of the WEEK. So is there a method to find out the current day of the WEEK
wich is a value 1-7 ?<br><br>Thank you,


0 Kudos
Message 3 of 6
(4,232 Views)
// Note that angle brackets around time.h stripped from message as invalid HTML


#include time.h //ANSI standard time/date library

int DayOfWeek() {
struct tm *newtime;
time_t long_time;

time(&long_time); // Get time as long integer.
newtime = localtime(&long_time); // Convert to local time.
dow = newtime->tm_wday; // Day Of Week - Days since Sunday 0-6
return dow;
} // End of DayOfWeek()
Message 4 of 6
(4,231 Views)
Hi,

Thank you! I'll keep that in mind for future posts.

George Hodgson

"TotalAJ" <x@no.email> wrote in message news:169797@exchange.ni.com...
> // Note that angle brackets around time.h stripped from message as invalid
HTML<br> <br><br>#include time.h //ANSI standard time/date
library<br><br>int DayOfWeek() {<br> struct tm *newtime;<br> time_t
long_time;<br><br> time(&long_time); // Get time as long integer.<br>
newtime = localtime(&long_time); // Convert to local time.<br> dow =
newtime->tm_wday; // Day Of Week - Days since Sunday 0-6<br> return
dow;<br>} // End of DayOfWeek()


0 Kudos
Message 5 of 6
(4,226 Views)

Yet another implementation...

 

double timeStamp;
int dayOfWeek = 0;
char dayString[10] = {0};

// Valid values are 0–6, where Sunday is 0
FormatDateTimeString(timeStamp, "%w", dayString, sizeof (dayString));
			
// convert to integer
sscanf(dayString, "%d", &dayOfWeek);			
0 Kudos
Message 6 of 6
(2,863 Views)