MSSQL DATE function [database query integer day or integer month]

Source: Internet
Author: User
Tags current time getdate mssql

MSSQL Date function [query integer day or integer month in database Tutorial]

Select//query for the entire month
*
From
Tb
where
DateDiff (hh, Time field, GETDATE ()) =0

Select DATEADD (Mm,2,getdate ())
Select DATEADD (Day,2,getdate ())


Query 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 ()

Querying all the data now

Select
*
From
Tb
where
DateDiff (hh, Time field, GETDATE ()) =0--When
and DateDiff (MI, Time field, GETDATE ()) =0--seconds

Using Stored Procedures

DECLARE @num int
Set @num =2
If DateAdd (d, @num, ' 2010-01-05 1:00 ') =getdate () or DATEADD (m,2, ' 2010-01-05 1:00 ') =getdate ()
print ' is '
Else
print ' not '

Detects whether the current time is longer than the whole number of days or months

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.