Asp.net time comparison

Source: Internet
Author: User
Tags net time

Generally, the time comparison is performed on the database end, but the time comparison is required on the Net Platform in recent development. There are two cases that should be more common. Now I will handle the correspondingCodePost as follows:

1. Validity of the date segment

For example, if "valid before-8-10 days", some operation can be performed in the past.

Datetime. Now. compareto (convert. todatetime ("2007-8-10 "))

Determine whether the return value is greater than 0. Note that system. argumentexception is caused by a parameter other than system. datetime ;)

2. Validity Period

For example, "valid from 8: 00 to 22 every day"

If (datetime. Now. Hour <8) | (datetime. Now. Hour> 22) {// invalid}

 

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.