1. 获取当前日期和时间:
SELECT CURRENT_TIMESTAMP;
2. 格式化日期:
SELECT TO_CHAR(CURRENT_DATE, 'YYYY-MM-DD') AS formatted_date;
3. 提取日期部分:
SELECT column1, EXTRACT(YEAR FROM column1) AS year_part FROM your_table;
4. 日期加法和减法:
SELECT column1, column1 + INTERVAL '7' DAY AS seven_days_later FROM your_table;
5. 计算日期差值:
SELECT DATEDIFF(day, column1, column2) AS day_difference FROM your_table;
6. 获取日期的某个部分:
SELECT column1, DAY(column1) AS day_part FROM your_table;
7. 使用当前日期进行过滤:
SELECT * FROM your_table WHERE column1 > CURRENT_DATE;
8. 计算时间间隔:
SELECT TIMEDIFF(time_column1, time_column2) AS time_difference FROM your_table;
9. 在日期上使用CASE表达式:
SELECT
column1,
CASE
WHEN column2 > CURRENT_DATE THEN 'Future'
WHEN column2 < CURRENT_DATE THEN 'Past'
ELSE 'Today'
END AS date_status
FROM your_table;
这些表达式提供了在OceanBase中处理日期和时间的灵活方式。你可以根据具体的业务需求使用这些表达式,进行日期和时间相关的计算和操作。
转载请注明出处:http://www.pingtaimeng.com/article/detail/11722/OceanBase