Oracle
field type is VARCHAR2, format to match formatted style
That day
SELECT * FROM table name where To_char (to_date (field name, ' Yyyy-mm-dd hh24:mi:ss '), ' DD ') =to_char (sysdate, ' DD ')
When the week
SELECT * FROM table name where To_char (to_date (field name, ' Yyyy-mm-dd hh24:mi:ss '), ' IW ') =to_char (sysdate, ' IW ')
Month
SELECT * FROM table name where To_char (to_date (field name, ' Yyyy-mm-dd hh24:mi:ss '), ' mm ') =to_char (sysdate, ' mm ')
When the quarter
SELECT * FROM table name where To_char (to_date (field name, ' Yyyy-mm-dd hh24:mi:ss '), ' Q ') =to_char (sysdate, ' Q ')
field type is date
That day
SELECT * FROM table name where To_char (field name, ' DD ') =to_char (sysdate, ' DDS ')
When the week
SELECT * FROM table name where To_char (field name, ' IW ') =to_char (sysdate, ' IW ')
Month
SELECT * FROM table name where To_char (field name, ' mm ') =to_char (sysdate, ' ' mm ')
When the quarter
SELECT * FROM table name where To_char (field name, ' Q ') =to_char (sysdate, ' Q ')
Sql
That day
SELECT * FROM table name where DATEPART (dd, field name) = DATEPART (dd, GETDATE ()) and DATEPART (mm, field name) = DATEPART (mm, GETDATE ()) and DATE Part (yy, field name) = DATEPART (yy, GETDATE ())
When the week
SELECT * FROM table name where DATEPART (wk, field name) = DATEPART (wk, GETDATE ()) and DATEPART (yy, field name) = DATEPART (yy, GETDATE ())
Month
SELECT * FROM table name where DATEPART (mm, field name) = DATEPART (mm, GETDATE ()) and DATEPART (yy, field name) = DATEPART (yy, GETDATE ())
When the quarter
SELECT * FROM table name where DATEPART (QQ, field name) = DATEPART (QQ, GETDATE ()) and DATEPART (yy, field name) = DATEPART (yy, GETDATE ())
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.