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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 62k
  • Answers 62k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I'll prefer the first option. 1) For code the readability… May 11, 2026 at 10:05 am
  • added an answer We have lots of customers who integrate QC defect and… May 11, 2026 at 10:05 am
  • added an answer parseInt() is just going to throw an exception if the… May 11, 2026 at 10:05 am

Related Questions

Given an amount of days, say 25, convert it into a duration text such
Given an absolute or relative path (in a Unix-like system), I would like to
Given an Oracle table created using the following: CREATE TABLE Log(WhenAdded TIMESTAMP(6) WITH TIME
Given an arbitrary string, what is an efficient method of finding duplicate phrases? We
Given an instance of System.Reflection.Assembly .
Given an array of n Objects, let's say it is an array of strings
Given an integer typedef: typedef unsigned int TYPE; or typedef unsigned long TYPE; I
Given an existing valid SVG document, what's the best way to create informational popups,
Given an MLS #, I'd like to get an XML document with details about
Given an array of characters which forms a sentence of words, give an efficient

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.