Day of year as base for calculation leap-year

Magnus1982

Registered User.
Local time
Today, 08:38
Joined
Apr 29, 2017
Messages
41
Hello
I am looking way to display in text box day of year .

I am using :

Dim iDayNumber As Integer
Dim dt As Date: dt = Date
iDayNumber = DateDiff("d", CDate("1/1/" & Year(dt)), dt) + 1

I have two problems:

1. If day in year is below 100 i have for example 89 or 7 I need to have 089 or 007.
2. Code need to count all the time base on 366days (leap-year) and should do not take into account an ordinary year.

Somebody know how to do that ?
 
Your post doesn't make sense about the leap years?
Are you trying to say you want to include Feb 29th even if it didn't exist that year ?

If not you simply need;
Code:
Format(datepart("y",Date()),"00#")
 
Yes exacly . I wanna include Feb 29 al the time. Even if not exist
 
I'm going to bite...

Why ? What's the purpose of this strangeness?
 
it was a rule during manufacturing process. Never mind. After internal discussion I just need regular day in year with 3 digit format
 
I think the idea is the staff are given the 29th Feb off every year that is not a leap year:):):)
 
it was a rule during manufacturing process. Never mind. After internal discussion I just need regular day in year with 3 digit format

Actually thanks for coming back to us with an answer. Sometimes we never get the real "behind the scenes" rational for strange requests.

I have actually written a function to do this for a laugh. :eek:

But stick with my original answer for simplicity.
 
This is called the Julian day.
See this thread for a lengthy discussion and several methods of deriving it: https://www.access-programmers.co.uk/forums/showthread.php?t=299464&highlight=Julian+day

If you want to include the year as well, this should do what you want:
Code:
Right(Year([DateField]), 2) & Format(DatePart("y", [DateField]),"000")

so today (14/08/2018) is 18226

Some more examples (using dd/mm/yyyy format):

attachment.php
 

Attachments

  • JulianDate.PNG
    JulianDate.PNG
    7.4 KB · Views: 132

Users who are viewing this thread

Back
Top Bottom