1. Preface
In daily development, we often use date functions to calculate dates or timestamps. The following briefly introduces the use of date functions of Wutong database and Gbase database.
2. Date addition and subtraction
1. GBase database
select cast('2024-10-30'as date) ± interval '1' day; --Date plus or subtract one day select cast('2024-10-30'as date) ± interval '1' year; --Date plus or subtract one year select cast('2024-10-30'as date) ± interval '1' month; --Date plus or minus one month select addDate(cast('2024-10-30'as date), interval '1' day/month/year); --Date plus one day/moon/Year select subDate(cast('2024-10-30'as date), interval '1' day/month/year); --Date reduced by one day/moon/Year select timestampdiff(month, cast('2024-01-01' as date), cast('2024-10-30'as date)); --计算两个日期之间moon份差 select add_months(cast('2024-01-01' as date), 10); --指定日期上加moon数
2. Wutong Database
select date'2024-10-30' ± 1 ; --Date plus or subtract one day select date'2024-10-30' ± interval '1 day'; --Date plus or subtract one day select date'2024-10-30' ± interval '1 year'; --Date plus or subtract one year select date'2024-10-30' ± interval '1 month'; --Date plus or minus one month select age(date'2023-10-30' , date'2024-10-30') --Calculate the difference between two dates
3. Add or subtract timestamps
1. GBase database
select current_time; --Get the current time select current_time ± interval '1' day; --Date plus or subtract one day select current_time ± interval '1' year; --Date plus or subtract one year select current_time ± interval '1' month; --Date plus or minus one month select current_time ± interval '1' hour; --Add or subtract the current time by one hour select current_time ± interval '1' minute; --Add or subtract the current time by one minute select current_time ± interval '1' second; --Add or subtract the current time by one second
2. Wutong Database
elect now(); --Get the current time select now() ± interval '1 day'; --Add or subtract time one day select now() ± interval '1 year'; --Time plus or subtract one year select now() ± interval '1 month'; --Time plus or minus one month select now() ± interval '1 hour'; --Add or subtract time by one hour select now() ± interval '1 minute'; --Add or subtract time by one minute select now() ± interval '1 second'; --Add or subtract time by one second select extract(epoch from (end_time - start_time)) ; --Calculate the number of seconds of the time stamp difference
4. Other date functions
- Timestamp conversion
--GBasedatabase: select from_unixtime('2024-10-30 15:29:24') --梧桐database: select to_timestamp('2024-10-30 15:29:24')
- Time intercept
--Wutong Database select extract(year from now()); -- Get Year select extract(month from now()); -- Get Month select extract(day from now()); -- Getting Day --Gbasedatabase select date_part('year', current_time) ; --Get Year select date_part('month', current_time) ; -- Get Month select date_part('day', current_time) ; -- Getting Day
4. Summary
Date functions are very important for our daily development and are often used. Wutong database and GBase database have rich date functions, which provide strong support for our development. The date function names of the two libraries are different, but their implementation functions are basically the same.
This is the end of this article about comparing Wutong database and GBase date function. For more information about comparing Wutong database and GBase date function, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!