MariaDB
 SQL >> Datenbank >  >> RDS >> MariaDB

UTC_TIME() in MariaDB: aktuelle UTC-Uhrzeit ohne Datum

Wenn nur die Uhrzeit gebraucht wird – nicht das Kalenderdatum – liefert die MariaDB-Funktion UTC_TIME() die aktuelle Zeit in der koordinierten Weltzeit (UTC), dem weltweiten Standard, der Zeitangaben unabhängig vom Standort der Server konsistent hält.

Wie ihre Datums- und Zeitverwandten passt sich das Rückgabeformat an den Kontext an: eine Zeichenkette im Format 'HH:MM:SS' oder ein numerischer Wert im Format HHMMSS.uuuuuu.

Syntax

Die Funktion akzeptiert ein optionales Präzisionsargument:

UTC_TIME UTC_TIME([precision])

Der Wert precision bestimmt die Anzahl der ausgegebenen Mikrosekunden-Stellen.

Grundlegendes Beispiel

Der Aufruf ist unkompliziert:

SELECT UTC_TIME, UTC_TIME();

Ergebnis:

+----------+------------+
| UTC_TIME | UTC_TIME() |
+----------+------------+
| 00:17:09 | 00:17:09   |
+----------+------------+

Präzision steuern

Um Mikrosekunden sichtbar zu machen, wird ein Präzisionswert angegeben:

SELECT UTC_TIME(3), UTC_TIME(6);

Ergebnis:

+--------------+-----------------+
| UTC_TIME(3)  | UTC_TIME(6)     |
+--------------+-----------------+
| 00:18:21.667 | 00:18:21.667957 |
+--------------+-----------------+

Numerischer Kontext

In einem numerischen Kontext kommt der Wert im Format HHMMSS.uuuuuu zurück:

SELECT UTC_TIME(6), UTC_TIME(6) + 0;

Ergebnis:

+-----------------+-----------------+
| UTC_TIME(6)     | UTC_TIME(6) + 0 |
+-----------------+-----------------+
| 23:01:18.921377 | 230118.921377   |
+-----------------+-----------------+

Ungültige Argumente

Ein nicht auswertbares Argument löst einen Syntaxfehler aus:

SELECT UTC_TIME('Six');

Ergebnis:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''Six')' at line 1