# 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?
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fabrice LambertCommented:
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)
``````
0
Petroleum ConsultantAuthor Commented:
I don't have the month. I have the number of days from the start of the year.
0
OwnerCommented:
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()
``````
0
Fabrice LambertCommented:
Then, use 1 as parameter value for the month. The resulting date will be adjusted.

DateSerial(2018, 1, 32) return 01/02/2018
DateSerial(2018, 1, 45) return 14/02/2018
DateSerial(2018, 1, 365) return 31/12/2018

(that's exactly what my code sample do).
0

Experts Exchange Solution brought to you by