In MySQL, you can use the WEEKDAY()
function to return the weekday index for a given date. Simply provide the date as an argument and the function will return the weekday index.
Category: DBMS
Database Management Systems
WEEK() Examples – MySQL
In MySQL, you can use the WEEK()
function to get the week number for a given date. By “week number” I mean the week of the year.
To use the function, simply provide the date as an argument and the week number will be returned.
You also have the option of specifying whether to start the week on Sunday or Monday, and whether the week should be in the range 0 to 53 or 1 to 53.
UTC_TIMESTAMP() Examples – MySQL
In MySQL, you can use the UTC_TIMESTAMP
function to return the UTC date and time. UTC stands for Coordinated Universal Time and it’s the primary time standard by which the world regulates clocks and time.
The result of this function is returned either in ‘YYYY-MM-DD HH:MM:SS’ or YYYYMMDDHHMMSS format, depending on whether it’s used in a string or numeric context.
UTC_TIME Examples – MySQL
In MySQL, you can use the UTC_TIME
function to return the UTC time. UTC stands for Coordinated Universal Time and it’s the primary time standard by which the world regulates clocks and time.
The result is returned either in ‘HH:MM:SS’ or HHMMSS format, depending on whether the function is used in a string or numeric context.
UTC_DATE Examples – MySQL
In MySQL, you can use the UTC_DATE
function to return the UTC date. UTC stands for Coordinated Universal Time and it’s the primary time standard by which the world regulates clocks and time.
The result is returned either in ‘YYYY-MM-DD’ or YYYYMMDD format, depending on whether the function is used in a string or numeric context.
TO_SECONDS() Examples – MySQL
In MySQL, the TO_SECONDS()
function returns the number of seconds since the year 0.
This function is not to be confused with the TIME_TO_SECONDS()
function, which returns the number of seconds in a given time value provided as an argument.
Continue reading
TIME_TO_SEC() Examples – MySQL
When using MySQL, you can use the TIME_TO_SEC()
function to return the number of seconds in a time value. Specifically, this function returns the time argument, converted to seconds.
This function is not to be confused with the TO_SECONDS()
function, which, given a date or datetime argument, returns the number of seconds since year 0.
Here’s how TIME_TO_SEC()
works.
TIME_FORMAT() Examples – MySQL
In MySQL, you can use the TIME_FORMAT()
function to format a time value.
This function works just like the DATE_FORMAT()
function, except that the value can only be formatted in hours, minutes, seconds, and microseconds.
See the table at the bottom of this article for a list of format specifiers that can be used with this function.
TIMESTAMPDIFF() Examples – MySQL
The MySQL TIMESTAMPDIFF()
function is used to find the difference between two date or datetime expressions. You need to pass in the two date/datetime values, as well as the unit to use in determining the difference (e.g., day, month, etc). The TIMESTAMPDIFF()
function will then return the difference in the specified unit.
TIMESTAMPADD() Examples – MySQL
In MySQL, the TIMESTAMPADD()
function allows you to add a specified amount of time to a date or datetime value. You specify the unit to add, as well as how many of that unit to add. It accepts three arguments, which are used for the initial value, the amount to add, and the unit to use.