Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1928212
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:57:04+00:00 2026-05-17T06:57:04+00:00

How to calculate days in years and months in c#? per example : If

  • 0

How to calculate days in years and months in c#?
per example :

If
1. days = 385 then I need to display Year= 1.1 (i.e. 1 year 1 month)
2. days= 234 then I need to display year =0.7 (i.e 0 year 7 months)

How can we calculate in c#?

I did for days=234 /365 and result is coming 0.64 (i.e. 0 year 6 months). But actually it is 7 months.

How to get accurate year and months.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T06:57:04+00:00Added an answer on May 17, 2026 at 6:57 am

    Assuming a month of exactly one-twelfth of a year, and that you want ignore partial months (based on your saying you expect 7 from your example with 7.688 months, then:

    int days = 234;
    double years = (double)days / 365.242199;
    int wholeYears = (int)Math.Floor(years);
    double partYears = years - wholeYears;
    double approxMonths = partYears * 12;
    string horribleFormat = string.Concat(wholeYears, ".", approxMonths);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Calculate Years, Months, weeks and Days How do I calculate difference in
How can I calculate the days between 1 Jan 2010 and (for example) 3
I need to calculate the number of days for a given month in python.
Possible Duplicates: How can I calculate the age of a person in year, month,
How can i calculate the number of days in a year for any calendar,
Possible Duplicate: How can I calculate the age of a person in year, month,
How can I calculate the number of work days between two dates in SQL
I need to calculate the timestamp of exactly 7 days ago using PHP, so
In C#, how can I calculate the number of business (or weekdays) days between
How to calculate shopping days till christmas counter in jQuery. need to add to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.