SoFunction
Updated on 2025-04-14

DM Dameng data date and time function and system function usage collection

introduction

In the fields of database management and data analysis, date-time functions and system functions are important tools for processing time series data, obtaining system information, and optimizing database operations. As a leading enterprise-level database system in China, Dameng Database provides rich date and time processing and system information acquisition functions. This article will introduce in detail several key date and time functions and system functions in the Dameng database, and analyze their usage through actual SQL examples to help you better utilize these functions to improve work efficiency.

1. Date and time function

1. CURRENT_DATE

Function: Return to the current date.

Example

SELECT CURRENT_DATE;

2. CURRENT_TIME

Function: Returns the current time (excluding the date part).

Example

SELECT CURRENT_TIME;

3. CURRENT_TIMESTAMP

Function: Returns the current date and time.

Example

SELECT CURRENT_TIMESTAMP;

4. DATE_FORMAT

Function: Format date or date time according to the specified format.

Example

SELECT DATE_FORMAT(CURRENT_TIMESTAMP, '%Y-%m-%d %H:%i:%s') AS formatted_time;

5. DATE_ADD

Function: Adds the specified time interval to the date.

Example: Calculate the date after one week.

SELECT DATE_ADD('DAY', 7, CURRENT_DATE) AS one_week_later;

6. DATEDIFF

Function: Calculate the time difference between two dates.

Example: Calculate the difference in the number of days during the two order days.

SELECT DATEDIFF('DAY', order_date, delivery_date) AS days_to_delivery
FROM orders;

2. System functions

1. USER

Function: Returns the user name of the currently logged in to the database.

Example

SELECT USER();

2. DATABASE()

Function: Returns the database name of the currently connected.

Example

SELECT DATABASE();

3. VERSION()

Function: Obtain the version information of the database server.

Example

SELECT VERSION();

4. SYSTEM_USER

Function: Returns the operating system user of the current database session.

Example

SELECT SYSTEM_USER;

5. SESSION_ID()

Function: Returns the ID of the current database session.

Example

SELECT SESSION_ID();

6. LAST_INSERT_ID()

Function: Get the automatic growth ID generated by the last insert operation.

Example

INSERT INTO users (username) VALUES ('new_user');
SELECT LAST_INSERT_ID();

Summarize

This is the article about the date and time functions of DM Dameng data and the usage of system functions. For more related contents of DM Dameng data, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!