Here’s a list of units that can be used in MySQL datetime and interval functions.
Continue readingCategory: MySQL
Concatenate a String and a Number in MySQL
There are a couple of approaches we can use to concatenate strings and numbers in MySQL.
- We can use the
CONCAT()
function, which concatenates its arguments. - We can use the pipe concatenation operator (
||
), which concatenates its operands.
Below are examples of each.
Continue readingHow to Enable the Pipe Concatenation Operator in MySQL
MySQL supports the use of the pipe concatenation operator (||
) for concatenating its operands. However, you need to enable it first.
Return the Day, Month, and Year in MySQL
MySQL has a bunch of different functions that enable us to get various date parts – such as the day, month, and year – from a date.
Continue readingYEAR() Examples – MySQL
In MySQL, YEAR()
is a built-in date and time function that returns the year from a given date expression.
It returns the year as a number in the range 1000
to 9999
. For zero dates, it could return 0
or NULL
with a warning, depending on the values in your sql_mode
.
How to Format Numbers as Currency in MySQL
Some DBMSs provide us with the ability to format a number as a currency by providing a format specifier for the currency symbol. Providing such a format specifier allows the DBMS to return the appropriate currency symbol for the locale.
MySQL doesn’t have a currency format specifier, and so we need to do a bit of extra work if we want the currency symbol to be returned.
Continue readingInstall MySQL on a Mac
Below are the steps that I used to install MySQL on my M1 Mac via the Homebrew package manager.
As mentioned, this is an M1 Mac (which uses the ARM64 architecture) but that didn’t cause any issues. The current version (MySQL 8.0.26) supports the ARM architechure.
Continue readingHow to Get the Short Month Name from a Date in MySQL
In MySQL, you can use the DATE_FORMAT()
function with the %b
format specifier to return the short month name. For example, you can return Jan
or Feb
instead of January
or February
.
List of MySQL Date Format Specifiers
Here’s a list of MySQL format specifiers that can be used in format strings with functions like DATE_FORMAT()
, STR_TO_DATE()
, and UNIX_TIMESTAMP()
.
Get the Month Name from a Date in SQL
Most major RDBMSs provide at least one function that enables us to return the month name from a date.
Continue reading