Determines whether the date expires and whether the date expires.

Source: Internet
Author: User

Determines whether the date expires and whether the date expires.

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 ~~


Oracle determines whether the date has expired (urgent)

Setting a trigger is unlikely, because the attacker does not automatically judge based on the system time.
You can set a job at every day and use the stored procedure to implement it.
Judge whether to_char (sysdate, 'yyyymmdd')> to_char (ReturnDate, 'yyyymmdd') at every day. Do you need not to mention it later?

How does asp add or subtract a date to determine if it expires?

There is a special function that gets the difference between two days!

Description
Returns the interval between two dates.
Syntax
DateDiff (interval, date1, date2 [, firstdayofweek [, firstweekofyear])
The syntax of the DateDiff function includes the following parameters:

Parameter description
Interval is required. String expression used to calculate the time interval between date1 and date2. For values, see the "Settings" section.
Date1 and date2 are required. Date expression. Two dates used for calculation.
Firstdayofweek is optional. Specify the constant of the first day of the week. If not specified, the default value is Sunday. For values, see the "Settings" section.
Firstweekofyear is optional. Specifies the constant of the first week of a year. If this parameter is not specified, the default value is the week of April 1, January 1. For values, see the "Settings" section.

Set
The interval parameter can have the following values:
Set description
Yyyy
Q quarter
M month
Y number of days in a year
D
Number of days per week
Ww week
H hour
M minutes
S seconds

The firstdayofweek parameter can have the following values:

Constant Value description
VbUseSystem 0 is set using the regional language (NLS) API.
VbSunday 1 Sunday (default)
VbMonday 2 Monday
VbTuesday 3 Tuesday
VbWednesday 4
VbThursday 5 Thursday
VbFriday 6 Friday
VbSaturday 7 Saturday

The firstweekofyear parameter can have the following values:

Constant Value description
VbUseSystem 0 is set using the regional language (NLS) API.
VbFirstJan1 starts from the week of July 1, January 1 (default ).
VbFirstFourDays 2 starts from the first week of at least four days in the New Year.
VbFirstFullWeek 3 starts from the first complete week of the year.

Description
The DateDiff function is used to determine the number of specified time intervals between two dates. For example, you can use DateDiff to calculate the number of days with different dates, or the number of weeks between the day and the last day of the current year.
To calculate the number of days for date1 and date2, you can use "number of days in a year" ("y") or "day" ("d "). When interval is "the number of days of a week" ("w"), DateDiff returns the number of weeks between two dates. If date1 is Monday, DateDiff calculates the number of Monday before date2. This result contains date2, not date1. If interval is "Week" ("ww"), the DateDiff function returns the number of weeks between two dates in the calendar table. Function compute the number of Sundays between date1 and date2. If date2 is Sunday, DateDiff calculates date2, but date1 is not calculated even if date1 is Sunday.

If date1 is later than date2, The DateDiff function returns a negative number.

The firstdayofweek parameter affects the calculation of the "w" and "ww" separators.

If date1 or date2 is a date text, the specified year will become a fixed part of the date. However, if date1 or date2 is included in quotation marks ("") and the year is omitted, the current year will be inserted every time date1 or date2 expressions are calculated in the code. In this way, you can write program code for different years.

If interval is "year" ("yyyy" ...... the remaining full text>
 

Related Article

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.