Below are 4 functions that enable you to return the microseconds part from a time value in MariaDB.
time format
How HOUR() Works in MariaDB
In MariaDB, HOUR() is a built-in date and time function that returns the hour from a given time expression.
It accepts one argument, which is the time you want to extract the hour from.
For time-of-day values, it returns the hour as a number in the range 0 to 23. However, the range of TIME values can be much larger, and therefore, the returned value can be much higher than 23.
The return value is always positive, even if a negative time is provided.
Convert a Date to Another Time Zone in SQL Server
The AT TIME ZONE clause was introduced in SQL Server 2016 to convert a date into a datetimeoffset value in a target time zone.
This function is similar to some other T-SQL functions, such as SWITCHOFFSET() and TODATETIMEOFFSET(), however, the AT TIME ZONE clause allows/(requires) you to specify the time zone offset by name, instead of an actual offset value.
This article explores how AT TIME ZONE works, and explains its benefits when compared to the other functions mentioned.
Get a List of Supported Time Zones in SQL Server (T-SQL)
SQL Server provides the sys.time_zone_info server-wide configuration view to return a list of supported time zones.
You can retrieve these with a simple SELECT statement.
Get the Current Time Zone of the Server in SQL Server (T-SQL)
Microsoft introduced the CURRENT_TIMEZONE() function in SQL Server 2019 for returning the time zone of the server.
More specifically, this function “returns the name of the time zone observed by a server or an instance”.
Format sysjobhistory datetime & duration Columns in SQL Server
If you’ve ever queried the sysjobhistory table in the msdb database, you’ll probably know that the datetime and duration columns are stored as integers.
In particular, when you query this table, the run_date, run_time, and duration columns are returned as integers, which can make it difficult to read.
Below is a query you can use to return this data in an easier to read format.
How to Add AM/PM to a Time Value in SQL Server (T-SQL)
In SQL Server, you can use the T-SQL FORMAT() function to format a time data type. However, if you need to add the AM/PM designator, you’ll need to use a different data type. This is because the time data type is specifically based on a 24 hour clock, and therefore the time is formatted as such.
Remember This When Formatting a TIME Data Type in SQL Server (T-SQL)
In SQL Server, when you use the T-SQL FORMAT() function to format a time data type, you need to remember to escape any colons or periods in your format string.
This is because theĀ FORMAT() function relies upon CLR formatting rules, which dictate that colons and periods must be escaped. Therefore, when the format string (second parameter) contains a colon or period, the colon or period must be escaped with backslash when an input value (first parameter) is of the time data type.