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?
Mohammed DallagPetroleum ConsultantAsked:
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 LambertFabrice 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)

Open in new window

0
Mohammed DallagPetroleum ConsultantAuthor Commented:
I don't have the month. I have the number of days from the start of the year.
0
David Johnson, CD, MVPOwnerCommented:
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

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Fabrice LambertFabrice 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

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mohammed DallagPetroleum ConsultantAuthor Commented:
thank you so much
0
David Johnson, CD, MVPOwnerCommented:
you don't need the month we hardcode the month as 1 then add days to that.
1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.