LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

[CVI2015] Get the day of the year from a given date

Solved!
Go to solution

Hello, 

 

How can I get the day of the year number from a given date ? (not necessarily the current date). 

 

Thanks in advance

0 Kudos
Message 1 of 3
(2,971 Views)

You can find some solutions here



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?
Message 2 of 3
(2,965 Views)
Solution
Accepted by topic author HoussamAz
#include <stdio.h>

int yisleap(int year)
{
    return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}

int get_yday(int mon, int day, int year)
{
    static const int days[2][13] = {
        {0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334},
        {0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}
    };
    int leap = yisleap(year);

    return days[leap][mon] + day;
}

int main(void)
{
    int day = get_yday(1, 31, 2013);

    printf("%d\n", day);
    return 0;
}

Thanks !

0 Kudos
Message 3 of 3
(2,944 Views)