ticks to months convert in c# RRS feed

  • Question

  • Hi,

    I have to convert ticks into months is there any way to do that? 



    Tuesday, May 28, 2013 5:28 PM


  • You can use something like:

    var span = TimeSpan.FromTicks(tickCount);
    int days = (int)span.TotalDays;
    // Assuming 30 day months, rounded to nearest
    int approximateMonths = (int)Math.Round(span.TotalDays / 30.0);

    Note that a "month" isn't a fixed length of time, so unless you know a start or end date, you can't get an exact number of months.

    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Proposed as answer by Enrique Ferreyra Tuesday, May 28, 2013 6:38 PM
    • Marked as answer by Mike Feng Tuesday, June 4, 2013 2:59 AM
    Tuesday, May 28, 2013 5:42 PM