Determine whether the date expires

Source: Internet
Author: User

In the user permission system, it is sometimes necessary to determine whether to expire based on the user's contract time and contract duration. First help class:

    public static class DateExprieHelper
    {
        /// <summary>
/// Determine whether to expire Based on the Contract Signing time and contract duration
        /// </summary>
/// <Param name = "joindate"> contract time </param>
/// <Param name = "duration"> contract duration </param>
        /// <returns></returns>
        public static bool IsExpriredByDay(DateTime joinDate, double duration)
        {
                return DateTime.Now - joinDate > TimeSpan.FromDays(duration);          
        }
    }

 

Client call.

    class Program
    {
        static void Main(string[] args)
        {
            var result = DateExprieHelper.IsExpriredByDay(new DateTime(2014, 1, 1), 365);
            if (result)
            {
Console. writeline ("expired ~~ ");
            }
            else
            {
Console. writeline ("not expired yet ~~ ");
            }
            Console.ReadKey();
        }
    }

The result shows that the instance has not expired ~~

Determine whether the date expires

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.