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 81647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:29:34+00:00 2026-05-10T21:29:34+00:00

Given an amount of days, say 25, convert it into a duration text such

  • 0

Given an amount of days, say 25, convert it into a duration text such as ‘3 Weeks, 4 Days’

C# and F# solutions would both be great if the F# variation offers any improvement over C#.

Edit: The solution should expand past weeks to include months and years. Bonus points for including centuries and so on. Extra bonus if it is somewhat configurable, meaning you can tell the method to exclude the normalization of weeks.

  • 1 1 Answer
  • 0 Views
  • 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. 2026-05-10T21:29:34+00:00Added an answer on May 10, 2026 at 9:29 pm

    This is a recursive solution. Note that a duration only really makes sense measured against a particular point in time on a given calendar because month and year lengths vary. But here is a simple solution assuming fixed lengths:

    let divmod n m = n / m, n % m      let units = [     ('Centuries', TimeSpan.TicksPerDay * 365L * 100L );     ('Years', TimeSpan.TicksPerDay * 365L);     ('Weeks', TimeSpan.TicksPerDay * 7L);     ('Days', TimeSpan.TicksPerDay) ]  let duration days =     let rec duration' ticks units acc =         match units with         | [] -> acc         | (u::us) ->             let (wholeUnits, ticksRemaining) = divmod ticks (snd u)             duration' ticksRemaining us (((fst u), wholeUnits) :: acc)     duration' (TimeSpan.FromDays(float days).Ticks) units [] 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to convert a given amount of days in a form to
How would I calculate the total amount of days a user has been absent
Given a table of the following form CustumerID | Amount ------------------- 1 | 100
I'm currently generating the amount of time given the number of seconds. This is
I know add() adds the specified (signed) amount of time to the given time
I have a table recording the amount of data transferred by a given service
given a Python class hierarchy, say class Base: def method1 def method2 def method3
I need a code snippet for converting amount of time given by number of
I need to sleep for a given amount of time and release monitors for
Mathematically we can solve it like Given Amount / Total Amount * 100 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.