mariadb-date-time-functions

Reference MariaDB date and time functions with signatures, semantics, and common pitfalls.

28|115|Updated Jan 28, 2025
One-click install
npx skills add https://github.com/mariadb-corporation/mariadb-docs --skill mariadb-date-time-functions-mariadb-corporation
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: mariadb-date-time-functions
Source: https://github.com/mariadb-corporation/mariadb-docs/tree/main/agent-skills/granular/functions/mariadb-date-time-functions
Command: npx skills add https://github.com/mariadb-corporation/mariadb-docs --skill mariadb-date-time-functions-mariadb-corporation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing correct date and time SQL in MariaDB is error-prone: NOW() versus SYSDATE() semantics, INTERVAL syntax requirements, week-numbering modes, time-zone table dependencies, and argument-order traps like TIMESTAMPDIFF cause subtle bugs. This Skill provides a complete catalog of all 64 built-in MariaDB date/time functions plus a curated list of the mistakes LLMs and developers most often make. ## Core Features & Use Cases - Complete function catalog: Signatures and one-line semantics for every date/time function, covering current time, arithmetic, differences, extraction, parsing/formatting, Unix time, time-zone conversion, and Oracle-compatible helpers. - Pitfall correction table: Maps common wrong assumptions (e.g., DATE_ADD(d, 7), DAYOFWEEK vs WEEKDAY indexing, CONVERT_TZ returning NULL) to the correct MariaDB form. - Version awareness: Functions annotated with the MariaDB version that introduced them, defaulting to 11.8 LTS context. - Use Case: When asked to compute the number of months between two timestamps, the Skill ensures you write TIMESTAMPDIFF(MONTH, start, end) with the unit first rather than guessing the argument order. ## Quick Start Ask the AI to write a MariaDB query that converts a UTC timestamp to Europe/Berlin and formats it, and it will apply the correct CONVERT_TZ and DATE_FORMAT usage from this Skill.

Frequently Asked Questions about mariadb-date-time-functions

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add days to a date in MariaDB?▼

Use DATE_ADD(d, INTERVAL 7 DAY) or the shorthand d + INTERVAL 7 DAY. Only ADDDATE(d, 7) and SUBDATE(d, 7) accept a bare integer as a days argument; DATE_ADD and DATE_SUB require the INTERVAL form.

What is the difference between NOW() and SYSDATE() in MariaDB?▼

NOW() and CURRENT_TIMESTAMP return the statement-start time and stay constant within a statement, while SYSDATE() returns the actual execution time and can differ between calls. SYSDATE() is non-deterministic, unsafe for statement-based replication, and prevents index use, so prefer NOW().

Why does CONVERT_TZ return NULL in MariaDB?▼

CONVERT_TZ returns NULL when a named time zone like 'Europe/Berlin' is unknown because the time-zone tables have not been loaded with mariadb-tzinfo-to-sql. Numeric offsets such as '+00:00' always work without loaded tables.

Does MariaDB support ADD_MONTHS and MONTHS_BETWEEN outside Oracle mode?▼

Yes, ADD_MONTHS, MONTHS_BETWEEN, and TRUNC are always available in any sql_mode. Only TO_DATE is Oracle-mode-specific, and it was added in MariaDB 12.3.

What is the maximum Unix timestamp MariaDB can handle?▼

On 64-bit builds since MariaDB 11.5, UNIX_TIMESTAMP and FROM_UNIXTIME support up to 4294967295, corresponding to 2106-02-07, and return NULL beyond it. For dates past that range, store values as DATETIME instead of TIMESTAMP.

How do DAYOFWEEK and WEEKDAY differ in MariaDB?▼

DAYOFWEEK() indexes days as 1 = Sunday through 7 = Saturday, while WEEKDAY() uses 0 = Monday through 6 = Sunday. Mixing the two shifts every weekday calculation, so pick one convention consistently.