Time functions in SQL

Source: Internet
Author: User
Tags date1

Mainly using database built-in functions

From: http://www.cnblogs.com/aijun/archive/2011/03/18/1987750.html

SQL queries today's records:

Datediff (day, [datetime], getdate () = 0 replace datetime with your corresponding field;

SQL query records of yesterday:

Datediff (day, [datetime], getdate () = 1 replace datetime with your corresponding field. getdate ()-datetime is the time difference.

This month's record:

Select * from table where datediff (month, [dateadd], getdate () = 0

Weekly record:

Select * from table where datediff (Week, [dateadd], getdate () = 0

Current day record:

Select * from table where datediff (day, [dateadd], getdate () = 0

 

 

function parameters/functions
getdate () returns the current date and time of the system
datediff (interval, date1, date2) returns the difference date2-date1 between date2 and date1 in the form specified by interval
dateadd (interval, number, date) Add the date after number in the format specified by interval
datepart (interval, date) return the integer corresponding to the part specified by interval in date
datename (interval, date) in date,

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.