Results 1 to 4 of 4

Thread: How to change numbers into years ,month and days.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    208

    Resolved How to change numbers into years ,month and days.

    I am developing web application using C#,ASP.net and ms sql server.
    now i have integer input example 402 days.
    now i want to express it in years, months and days.
    that is
    1 year, 1 month and 7 days.
    so how can i do this?
    thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: How to change numbers into years ,month and days.

    You can't do it reliably unless you have a reference date, because the same number of total days might represent a different number of years, months and days depending on which months of which years it spans. That's because of leap years and the fact that different months contain different numbers of days.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    208

    Re: How to change numbers into years ,month and days.

    on sorry. yes i have a reference date.
    i have a registration form. it has a column which is dateOfJoining.
    example. MR Girmay joined the company in Nov -10-2011 and
    now he wants to leave the company after he spend 402 days.
    so how do i convert his expedience, in to years and months and days...
    thanks

  4. #4
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: How to change numbers into years ,month and days.

    Try this, you just need to add a label to the page.

    C# Code:
    1. protected void Page_Load(object sender, EventArgs e)
    2.         {
    3.            
    4.             DateTime d = new DateTime(2011, 10, 11);
    5.             this.Label1.Text = d.AddDays(402).ToString();
    6.         }
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width