Get time SQL Function statement

Source: Internet
Author: User
Tags getdate

1. Get Time

  Get data for the day

where DATEDIFF (DD, field of time in database, GETDATE ()) =0

Query within 24 hours of

where DATEDIFF (HH, field of time in database, GETDATE ()) =0

  Get data for the week

where DATEDIFF (WEEK, Dt_uploadtime, GETDATE ()) =0

* Get data for this week, if it's Monday or no data, you can simulate nearly a week of data *:where DATEDIFF (DD, the field of time in the database, GETDATE ()) <=7

  Get the data for this month

where DATEDIFF (MONTH, Dt_uploadtime, GETDATE ()) =0

* Get data for this month, similar to a week, a number maybe no data, can simulate the data of nearly January *:where DATEDIFF (DD, the field of time in the database, GETDATE ()) <=30

   system Date Time : getdate ()

   Add a time or a period of time to a date

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

   function : Datadiff (datepart,startdate,enddate) * returns the number of date and time boundaries across two specified dates *

Select DateDiff (Day, ' 2004-09-01 ', ' 2004-09-18 ')--return:

DATEPART () * Returns an integer representing the specified date part of the specified date *

SELECT DATEPART (month, ' 2004-10-15 ')--return

or use day (), month (), year (), and so on.

Datename () * Returns a string representing the specified date part of the specified date *

     SELECT Datename (Weekday, ' 2004-10-15 ')--return: Friday

2. Paging

SELECT * FROM (select Row_number () up (order by dt_uploadtime desc) as num, * from Photo)

As TBL

where Tbl.num between (@pageIndex-1) *pagenum+1 and @pageIndex * @pageNum

   PageIndex: Represents the current page Pagenum: Indicates the number of bars displayed per page

Get time SQL Function statement

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.