Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

php - Convert x number of days to decimal year

I have a number of X days, let's say 700. How can I output this 700 to years? Eg. 700 = 1.11 years (1 year 11 months) or 2.2 (2 years and two months) ... And so on

I don't care for leap years or such, just need an aproximate value.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Think about it...

700 days, 30 days in a month.

700/30 = 23.33 months. 12 months in a year.

23.33/12 = 1.944444... take the integer value (int)1.944444 to get 1 for the year.

23.33%12= 11.33... months. You can cast it to an int as well to get 11

Your result: 1 year, 11 months


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...