Link to home
Start Free TrialLog in
Avatar of Master Work
Master Work

asked on

If I have the year and the number of days in that year, how can I know the date?

If I have the year and the number of days in that year, how can I know the date?
Avatar of Fabrice Lambert
Fabrice Lambert
Flag of France image

Hi,

Use the DateSerial function as it always return a valid date.
If parameters are out of "traditional" values, the result will be adjusted.

Sample code:
Dim theYear As Integer
theYear = 2018

Dim theDay As Integer
theDay = 45

Dim dt As Date
dt = DateSerial(theYear, 1, theDay)

Open in new window

Avatar of Master Work
Master Work

ASKER

I don't have the month. I have the number of days from the start of the year.
into a cell. then have a cell = 1/1/yy + (days-1)
this will be the date for that number of days in year yy.
if you have
year = 2018
daynumber = 20
stryear= "01-Jan-" + year.tostring()
DateAdd("d", daynumber, stryear)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Fabrice Lambert
Fabrice Lambert
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank you so much
you don't need the month we hardcode the month as 1 then add days to that.