tencent cloud

TencentDB for MySQL

Release Notes and Announcements
Release Notes
Product Announcements
User Tutorial
Product Introduction
Overview
Strengths
Use Cases
Database Architecture
Resource Isolation Policy
Economical Instance
Feature List
Database Instance
High Availability (Multi-AZ)
Regions and AZs
Service Regions and Service Providers
Kernel Features
Overview
Kernel Version Release Notes
Functionality Features
Performance Features
Security Features
Stability Features
TXRocks Engine
LibraDB Engine
Checking and Fixing Kernel Issues
Purchase Guide
Billing Overview
Selection Guide
Purchase Methods
Renewal
Payment Overdue
Refund
Pay-as-You-Go to Monthly Subscription
Instance Adjustment Fee
Backup Space Billing
Database Audit Billing Overview
Commercial Billing and Activity Description for Database Proxy
Description of the Database Proxy Billing Cycle
Viewing Bills
Getting Started
Overview
Creating MySQL Instance
Connecting to MySQL Instance
SQL Insight (Database Audit)
Overview
Viewing Audit Instance List
Enabling Audit Service
Viewing Audit Log
Log Shipping
Configuring Post-Event Alarms
Modifying Audit Rule
Modifying Audit Services
Disabling Audit Service
Audit Rule Template
SQL Audit Rule (Legacy)
Viewing Audit Task
Authorizing Sub-User to Use Database Audit
MySQL Cluster Edition
Introduction to TencentDB for MySQL Cluster Edition
Creating TencentDB for MySQL Cluster Edition Instance
Maintenance Management Instance
Viewing Instance Monitoring
Adjusting Instance Configuration
Operations for Other Features
Migrate or upgrade to TencentDB for MySQL Cluster Edition
Operation Guide
Use Limits
Operation Overview
Instance Management and Maintenance
Instance Upgrade
CPU Elastic Expansion
Read-Only/Disaster Recovery Instances
Database Proxy
Database Management Center (DMC)
Account Management
Parameter Configuration
Backup and Rollback
Data Migration
Network and Security
Monitoring and Alarms
Log Center
Read-Only Analysis Engine
Tag
Practical Tutorial
Using TencentDB for MySQL to Upgrade MySQL 5.7 to MySQL 8.0
Methods and Instructions for Upgrading from MySQL 5.6 to MySQL 5.7
Cybersecurity Classified Protection Practice for Database Audit of TencentDB for MySQL
Building All-Scenario High-Availability Architecture
Usage Specifications of TencentDB for MySQL
Configuring Automatic Application Reconnection
Impact of Modifying MySQL Source Instance Parameters
Limits on Automatic Conversion from MyISAM to InnoDB
Creating VPCs for TencentDB for MySQL
Enhancing Business Load Capacity with TencentDB for MySQL
Setting up 2-Region-3-DC Disaster Recovery Architecture
Improving TencentDB for MySQL Performance with Read/Write Separation
Migrating Data from InnoDB to RocksDB with DTS
Building LAMP Stack for Web Application
Building Drupal Website
Calling MySQL APIs in Python
The primary and secondary instances have inconsistent query data
White Paper
Performance White Paper
Security White Paper
Troubleshooting
Connections
Performance
Instance Data Sync Delay
Failure to Enable Case Insensitivity
Failure to Obtain slow_query_log_file via a Command
API Documentation
History
Introduction
API Category
Instance APIs
Making API Requests
Data Import APIs
Database Proxy APIs
Database Audit APIs
Security APIs
Task APIs
Backup APIs
Account APIs
Rollback APIs
Parameter APIs
Database APIs
Monitoring APIs
Log-related API
Data Types
Error Codes
FAQs
Related to Selection
Billing
Backup
Rollback
Connection and Login
Parameter Modifications
Instance Upgrade
Account Permissions
Performance and Memory
Ops
Data Migration
Features
Console Operations
Logs
Event
Database audit
Instance Switch Impact
API 2.0 to 3.0 Switch Guide
Service Agreement
Service Level Agreement
Terms of Service
Reference
Standards and Certifications
Contact Us
Glossary

Description of Supported Date Functions

PDF
Focus Mode
Font Size
Last updated: 2025-12-03 14:23:21
The read-only analysis engine currently supports most MySQL date functions, but there are still limitations and incompatibilities in some scenarios. This document introduces the supported list of date functions in the read-only analysis engine and lists the type limitations in input parameters. If input parameters and functions are not mentioned in the document, they are not supported.

Supported Date Functions

datediff Function

A function that calculates the number of specified time intervals between two dates.
Syntax: datediff(date1, date2)
Supported value types for date1: Date and datetime data.
Supported value types for date2: Date and datetime data.

year Function

A function that calculates the year.
Syntax: year(date1)
Supported value types for date1: Date, datetime, char, and varchar data.

month Function

A function that calculates the month.
Syntax: month(date1)
Supported value types for date1: Date, datetime, char, and varchar data.

day Function

A function that calculates the current day number.
Syntax: day(date1)
Supported value types for date1: Date, datetime, char, and varchar data.

hour Function

A function that calculates the hour.
Syntax: hour(date1)
Supported value types for date1: Date and datetime data.

minute Function

A function that calculates the minute.
Syntax: minute(date1)
Supported value types for date1: Date and datetime data.

second Function

A function that calculates the second.
Syntax: second(date1)
Supported value types for date1: Date and datetime data.

microsecond Function

A function that returns the microsecond part of the time/date and time.
Syntax: microsecond(date1)
Supported value types for date1: Date and datetime data.

quarter Function

A function that returns the quarter of the year for the given date value (a number between 1 and 4).
Syntax: quarter(date1)
Supported value types for date1: Date, datetime, varchar, and char data.

date Function

Date function.
Syntax: date(date1)
Supported value types for date1: Date, datetime, char, and varchar data.

sysdate Function

A function that returns system time.
Syntax: sysdate()

date_add Function

A function that adds dates.
Syntax: date_add(date1, interval expr type)
Supported value types for date1: Date and datetime data.
Supported value types for expr: int, long, double, and decimal.
Supported value types for type: DAY, which is a keyword.

date_sub Function

A function that subtracts dates.
Syntax: date_sub(date1, interval expr type)
Supported value types for date1: Date and datetime data.
Supported value types for expr: int, long, double, and decimal.
Supported value types for type: DAY, which is a keyword.

dayofyear Function

A function that returns the day of the year for a given date.
Syntax: dayofyear(date1)
Supported value types for date1: Date, datetime, char, and varchar data.

dayofmonth Function

A function that returns the day of the month for a given date.
Syntax: dayofmonth(date1)
Supported value types for date1: Date, datetime, char, and varchar data.

dayofweek Function

A function that returns the day of the week for a given date.
Syntax: dayofweek(date1)
Supported value types for date1: Date, datetime, char, and varchar data.

dayname Function

A function that returns the name of the day of the week corresponding to the specified date.
Syntax: dayname(date1)
Supported value types for date1: Date, datetime, char, and varchar data.

monthname Function

A function that returns the name of the month corresponding to the specified date.
Syntax: monthname(date1)
Supported value types for date1: Date, datetime, char, and varchar data.

to_seconds Function

A function that returns the number of seconds counting from year 0 to the specified date/date and time.
Syntax: to_seconds(date1)
Supported value types for date1: Date, datetime, char, and varchar data.

last_day Function

A function that returns the last day of the month.
Syntax: last_day(date1)
Supported value types for date1: Date, datetime, char, and varchar data.

sleep Function

A function that pauses for a few seconds during execution.
Syntax: sleep(N)
Supported value types for N: int data.

now Function

A function that obtains the current time.
Syntax: NOW()
Obtain the current time without input parameters.

current_timestamp Function

A function that obtains the current time, equivalent to the NOW function.
Syntax: CURRENT_TIMESTAMP()
Obtain the current time without input parameters.

curdate Function

A function that obtains the current date, equivalent to the CURRENT_DATE function.
Syntax: CURDATE()
Obtain the current date without input parameters.

current_date Function

A function that obtains the current date, equivalent to the CURDATE function.
Syntax: CURRENT_DATE()
Obtain the current time without input parameters.

current_time Function

A function that obtains the current time.
Syntax: CURRENT_TIME()
Obtain the current time without input parameters.

curtime Function

A function that obtains the current time, equivalent to the CURRENT_TIME function.
Syntax: CURTIME()
Obtain the current time without input parameters.

from_unixtime Function

A function that converts timestamp to time format.
Syntax: FROM_UNIXTIME(unix_timestamp[,format])
unix_timestamp supports int type numbers.
The formats supported by format are shown in the table of date_format function below. If format is empty, the default format is %Y-%m-%d %H:%i:%s.

unix_timestamp Function

A function that converts date and time to timestamp.
Syntax: UNIX_TIMESTAMP([date])
date supports the date type of the DATE standard.
Note:
Only 1.2404.17.0 and later versions support the FROM_UNIXTIME function and the UNIX_TIMESTAMP function.

weekday Function

A function that obtains the week corresponding to the parameter value.
Syntax: weekday(date)
This function obtains the number of weeks corresponding to a date. The input parameter supports Date or Datetime values. The returned result range is 0 to 6, which respectively corresponds to Sunday to Saturday. If the date is NULL or 0000-00-00, the function returns NULL.

timediff Function

Obtain the difference between two times.
Syntax: timediff(time1,time2)
Obtain the time difference between time1 and time2 (time1 - time2).

to_days Function

A function that obtains the number of days between December 31, 0 A.D. and the input parameter value.
Syntax: to_days(date)
This function obtains the number of days between the input value and 0 A.D. The input parameter supports Date or string values. The returned result is of numeric type.

yearweek Function

This function is used to obtain the year and week number of a specified date.
Syntax: yearweek(date[,mode])
This function returns a week number. In this function, date is the date to be calculated (for example, "2025-06-15"); mode is an optional parameter used to specify the start day of a specified week. The value of this parameter is 0 by default, indicating that the start day of a week is Sunday. The return result is of the numeric type.

time Function

This function is used to obtain the time part of a time or date expression and returns a string.
Syntax: time(expr)
This function returns the time. expr can be the time type or the date and time type. The return value is a string. If expr is empty, an empty result will be returned.

date_format Function

A function that formats a date.
Syntax: date_format(date1, format)
Supported value types for date1: Date, datetime, char, and varchar data, and do not support date1 containing null scenarios. format specifies the output format of date/time. The available formats are shown in the table below.
Format
Description
%a
Abbreviated names of the days of the week.
%b
Abbreviated names of the months.
%c
Month and numeric value.
%D
Days of the month with English prefixes.
%d
Day of the month; numeric value (00 - 31).
%e
Day of the month; numeric value (0 - 31).
%f
Microsecond.
%H
Hour (00 - 23).
%h
Hour (01 - 12).
%I
Hour (01 - 12).
%i
Minute; numeric value (00 - 59).
%j
Day of the year (001 - 366).
%k
Hour (0 - 23).
%l
Hour (1 - 12).
%M
Names of the months.
%m
Month; numeric value (00 - 12).
%p
AM or PM.
%r
Time; 12-hour clock (hh:mm:ss AM or PM).
%S
Second (00 - 59).
%s
Second (00 - 59).
%T
Time; 24-hour clock (hh:mm:ss).
%U
Week (00 - 53). Sunday is the first day of the week.
%u
Week (00 - 53). Monday is the first day of the week.
%V
Week (01 - 53). Sunday is the first day of the week, used with %X.
%v
Week (01 - 53). Monday is the first day of the week, used with %x.
%W
Names of the days of the week.
%w
Day of the week (0 = Sunday; 6 = Saturday).
%X
Year, where Sunday is the first day of the week. The value contains 4 digits, used with %V.
%x
Year, where Monday is the first day of the week. The value contains 4 digits, used with %v.
%Y
Year (4 digits).
%y
Year (2 digits).

Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback