Sign in to follow this  
Followers 0
pavilion

How To Calculate the Day of The Year

3 posts in this topic

Hi, I am looking for CODE "calculate the day of the year". I want to count number of day... I want to know how may day from Jan 1, to Dec 31.... Please help...

Share this post


Link to post
Share on other sites
Do you need to know the current day of the year, eg a number between 1 and 366 or do you want to know how many days in a year, eg 365 or 366.

Share this post


Link to post
Share on other sites
Since you didn't specify a specific AD PLC I won't give actual code. But I assume you at least have a real time clock which gives at least 'year (00-99)', 'month (1 - 12)' and 'day of month (1 - ??) Set up a table of 11 entries with the days in a month (show February as 28). You don't need an entry for December. 'Day of Year' = 0 If Month > 1 then For X = 1 to (Month - 1) 'Day Of Year' = 'Day Of Year' + table[X] Next X End If 'Day Of Year' = 'Day Of Year" + 'Day Of Month' If MOD(Year /4) = 0 AND Month > 2 then 'Day Of Year' = 'Day Of Year' + 1 End If Now - translate that into code of your target PLC. Since the Leap Year test works from 1901 through 2099 if figured that it is detailed enough. Edited by b_carlton

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0