Mssql date function [query integer days or integer months in the database]

Source: Internet
Author: User
Mssql date function [query integer days or integer months] select to query the entire month's & nbsp; * from & nbsp; tbwhere & nbsp; datediff (hh, time field, getdate ()) 0 & nbsp; selectdateadd (mm, 2, getdate () selectdateadd (day, 2, getdate ()) query day and hour da mssql date functions [query integer days or integer months]

Select // query
*
From
Tb
Where
Datediff (hh, time field, getdate () = 0

Select dateadd (mm, 2, getdate ())
Select dateadd (day, 2, getdate ())


// Query the day and hour

Datediff (dd, time, getdate () -- day
Datediff (hh, time, getdate () -- hour

// Query the current

Select * from # tb where dateadd (mm, 2, datacol) = getdate ()

// Query all current data

Select
*
From
Tb
Where
Datediff (hh, time field, getdate () = 0 -- hour
And datediff (mi, time field, getdate () = 0 -- Second

// Use

Declare @ num int
Set @ num = 2
If dateadd (d, @ num, '2017-01-05 ') = getdate () or dateadd (m, 2, '2017-01-05 ') = getdate ()
Print 'yes'
Else
Print 'Not'

// Check whether the current time has exceeded an integer day or an integer month than the saved time.

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.