Description\n-----------\n\nThe TIME, DATETIME, and TIMESTAMP types, along with the temporal functions, CAST and dynamic columns, support microseconds. The datetime precision of a column can be specified when creating the table with CREATE TABLE, for example:\n\n``sql\nCREATE TABLE example(\n  col_microsec DATETIME(6),\n  col_millisec TIME(3)\n);\n`\n\nGenerally, the precision can be specified for any TIME, DATETIME, or TIMESTAMP column, in parentheses, after the type name. The datetime precision specifies number of digits after the decimal dot and can be any integer number from 0 to 6. If no precision is specified it is assumed to be 0, for backward compatibility reasons.\n\nA datetime precision can be specified wherever a type name is used. For example:\n\n when declaring arguments of stored routines;\n when specifying a return type of a stored function;\n when declaring variables;\n in a CAST function.\n\n`sql\nCREATE FUNCTION example(x DATETIME(5)) RETURNS TIME(4)\nBEGIN\n DECLARE y TIMESTAMP(6);\n RETURN CAST(x AS time(2));\nEND;\n`\n\n%f is used as the formatting option for microseconds in the STR_TO_DATE, DATE_FORMAT and FROM_UNIXTIME functions, for example:\n\n`sql\nSELECT STR_TO_DATE('20200809 020917076','%Y%m%d %H%i%s%f');\n+-----------------------------------------------------+\n| STR_TO_DATE('20200809 020917076','%Y%m%d %H%i%s%f') |\n+-----------------------------------------------------+\n| 2020-08-09 02:09:17.076000                          |\n+-----------------------------------------------------+\n`\n\nAdditional Information\n\n When comparing anything to a temporal value (DATETIME, TIME, DATE, or TIMESTAMP), both values are compared as temporal values, not as strings.\n The INFORMATION_SCHEMA.COLUMNS table has a new column DATETIME_PRECISION\n NOW(), CURTIME(), UTC_TIMESTAMP(), UTC_TIME(), CURRENT_TIME(), CURRENT_TIMESTAMP(), LOCALTIME() and LOCALTIMESTAMP() accept datetime precision as an optional argument. For example:\n\n`sql\nSELECT CURTIME(4);\n--> 10:11:12.3456\n`\n\n TIME_TO_SEC() and UNIX_TIMESTAMP() preserve microseconds of the argument. These functions will return a decimal number if the result non-zero datetime precision and an integer otherwise (for backward compatibility).\n\n`sql\nSELECT TIME_TO_SEC('10:10:10.12345');\n--> 36610.12345\n`\n\n Current versions of this patch fix a bug in the following optimization: In certain queries with DISTINCT MariaDB can ignore this clause if it can prove that all result rows are unique anyway, for example, when a primary key is compared with a constant. Sometimes this optimization was applied incorrectly, though — for example, when comparing a string with a date constant. This is now fixed.\n DATE_ADD() and DATE_SUB() functions can now take a TIME expression as an argument (not just DATETIME as before).\n\n`sql\nSELECT TIME('10:10:10') + INTERVAL 100 MICROSECOND;\n--> 10:10:10.000100\n`\n\n The event_time field in the mysql.general_log table and the start_time, query_time, and lock_time fields in the mysql.slow_log table now store values with microsecond precision.\n The old syntax TIMESTAMP(N), where N is the display width, is no longer supported.\n When a DATETIME value is compared to a TIME value, the latter is treated as a full datetime with a zero date part, similar to comparing DATE to a DATETIME, or to comparing DECIMAL numbers.\\\n  Earlier versions of MariaDB used to compare only the time part of both operands in such a case.\n In MariaDB, an extra column TIME_MS has been added to the INFORMATION_SCHEMA.PROCESSLIST table, as well as to the output of SHOW FULL PROCESSLIST.\n\nNote: When you convert a temporal value to a value with a smaller precision, it will be truncated, not rounded. This is done to guarantee that the date part is not changed. For example:\n\n`sql\nSELECT CAST('2009-12-31 23:59:59.998877' AS DATETIME(3));\n-> 2009-12-31 23:59:59.998\n``\n\nURL: https://mariadb.com/docs/server/reference/sql-functions/date-time-functions/microseconds-in-mariadb