Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the date query statement and display format commonly used in SQL

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article Xiaobian for you to introduce in detail "SQL commonly used date query statement and display format setting is what", detailed content, clear steps, details handled properly, I hope that this "SQL commonly used date query statement and display format setting is what" article can help you solve doubts, following the editor's ideas slowly in-depth, together to learn new knowledge bar.

1. Query the current year, month and week related time 1.1. Query current year SELECT TO_CHAR (SYSDATE,'YYYY') AS YEAR FROM DUAL-- query current year SELECT TO_CHAR (SYSDATE,'YYY') AS YEAR FROM DUAL-- query current year after two-bit SELECT TO_CHAR (SYSDATE,'YY') AS YEAR FROM DUAL-- query current year last two-bit SELECT TO_CHAR (SYSDATE,'Y') AS YEAR FROM DUAL-- query current year last digit 1.2. Query the date of the current year SELECT TO_CHAR (SYSDATE,'DDD') AS DAYS FROM DUAL1.3. Query the date of the current month SELECT TO_CHAR (SYSDATE,'DD') AS DAYS FROM DUAL1.4. Query the day of the current week SELECT TO_CHAR (SYSDATE,'dy') AS WEEK FROM DUALSELECT TO_CHAR (SYSDATE,'day') AS WEEK FROM DUAL1.5. Query the day of the year before last: SELECT TO_CHAR (SYSDATE,'DDD') AS DAYS FROM DUAL2. Query the current quarter of SELECT TO_CHAR (SYSDATE,'Q') AS JD FROM DUAL3. SELECT TO_CHAR (SYSDATE,'IW') AS WEEKNUM FROM DUALSELECT TO_CHAR (SYSDATE,'WW') AS WEEKNUM FROM DUALSELECT TO_CHAR (SYSDATE,'W') AS WEEKNUM FROM DUAL4. Query the current number of days in a certain month of a year SELECT TO_CHAR (last_day (to_date ('20119 Universe 02 Universe)),' DD') AS MONTH_DAYS_NUMBER FROM DUAL5. Query the current date format SELECT TO_CHAR (SYSDATE,'YYYY/MM/DD') AS MONTH FROM DUAL-- to get the current date's' YYYY/MM/DD' format: 2020/01/02SELECT TO_CHAR (SYSDATE,'YYYYMMDD') AS MONTH FROM DUAL-- get the current date's' YYYYMMDD' format: 20200102SELECT TO_CHAR (SYSDATE,'YYYYMMDD HH:MI:SS') AS now FROM DUAL-- to get the current time Accurate to second 12-hour format: 20200102 03:18:25SELECT TO_CHAR (SYSDATE,'YYYYMMDD HH24:MI:SS') AS now FROM DUAL-- to get the current time, accurate to the second 24-hour format: 20200102 15:18:13SELECT TO_CHAR (SYSDATE,'YYYY/MM/DD HH24:MI:SS:PM:DY') AS now FROM DUAL-- to get the current time format Show morning, afternoon and day of the week: 15:17:59 on 2020-01-02: afternoon: Thursday 6. The time interval between the query and the current time Use "+" SELECT TO_CHAR (SYSDATE, 'YYYY/MM/DD HH24:MI:SS') AS NOW,TO_CHAR (SYSDATE-INTERVAL' 7' second,'YYYY/MM/DD HH24:MI:SS') AS PAST FROM DUAL after "-" current time-query the current time 7 seconds ago SELECT TO_CHAR (SYSDATE, 'YYYY/MM/DD HH24:MI:SS') AS NOW,TO_CHAR (SYSDATE-INTERVAL' 7' minute) 'YYYY/MM/DD HH24:MI:SS') AS PAST FROM DUAL-- query 7 minutes before the current time SELECT TO_CHAR (SYSDATE,' YYYY/MM/DD HH24:MI:SS') AS NOW,TO_CHAR (SYSDATE-INTERVAL '7'hour,' YYYY/MM/DD HH24:MI:SS') AS PAST FROM DUAL-- query 7 hours before the current time SELECT TO_CHAR (SYSDATE, 'YYYY/MM/DD HH24:MI:SS') AS NOW TO_CHAR (SYSDATE-INTERVAL '7'day,' YYYY/MM/DD HH24:MI:SS') AS PAST FROM DUAL-query 7 days before the current time SELECT TO_CHAR (SYSDATE, 'YYYY/MM/DD HH24:MI:SS') AS NOW,TO_CHAR (SYSDATE-INTERVAL' 7'month, 'YYYY/MM/DD HH24:MI:SS') AS PAST FROM DUAL-query the current pre-July time SELECT TO_CHAR (SYSDATE) 'YYYY/MM/DD HH24:MI:SS') AS NOW,TO_CHAR (SYSDATE-INTERVAL' 7'year, 'YYYY/MM/DD HH24:MI:SS') AS PAST FROM DUAL-query the current time 7 years ago SELECT TO_CHAR (SYSDATE,' YYYY/MM/DD HH24:MI:SS') AS NOW,TO_CHAR (SYSDATE-8*INTERVAL '7'hour) 'YYYY/MM/DD HH24:MI:SS') AS PAST FROM DUAL-- query the current time parameters year, month, day, hour, minute, second multiplied by a numeric multiple. This article "SQL commonly used date query sentence and display format setting" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report