Processing of some date Conditions

Source: Internet
Author: User

I encountered a problem today. I want to query the data added to a table today and solve it later. Well, record it:

Select * from table 1 where convert (varchar (10), table 1. Creation Time, 120) = convert (varchar (10), getdate (), 120)

For this month:

Select * from table 1 where convert (varchar (7), table 1. Creation Time, 120) = convert (varchar (7), getdate (), 120)

For this purpose, I checked the date function and recorded it:

1. dateadd adds a period of time to the specified date and returns a new datetime value, for example, dateadd (day, 2, '2017-09-22 ')

2. datediff returns the time difference between two dates, for example, datediff (day, '2017-09-22 ', '2017-09-18 '): returns the number of days between two dates (the last minus the previous one)

3. datepart returns the integer of the specified date part of the specified date, for example, datepart (month, '2017-10-15 ')

4. datename returns the string of the specified date part of the specified date, for example, select datename (weekday, '2017-10-15 ') -- Return: Friday

Finally, remember that getdate () is used to obtain the current time.

Processing of some date Conditions

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.