segunda-feira, 20 de julho de 2015

DateDiff C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lapuinka.Utils
{
    public static class Extensions
    {
        public static int DateDiff(this DateTime Data1, DateTime Data2, DatePart Part)
        {
            TimeSpan s = Data1 - Data2;
            switch (Part)
            {
                case DatePart.Segundos:
                    return s.Seconds;
                    break;
                case DatePart.Minutos:
                    return s.Minutes;
                    break;
                case DatePart.Horas:
                    return s.Hours;
                    break;
                case DatePart.Dias:
                    return s.Days;
                    break;
                default:
                    return -1;
                    break;
            }
        }
    }
}



Postar um comentário