The following table contains a full list of format specifiers that can be used in format strings with functions like DATE_FORMAT()
, STR_TO_DATE()
, and FROM_UNIXTIME()
in MySQL.
Tag: dates
How to Set Up Named Time Zones in MySQL
If you want to use named time zones in MySQL, you’ll need to make sure they’ve been configured.
By “named time zones”, I mean being able to use strings like US/Eastern
instead of −04:00
or −05:00
when specifying the time zone. For example, when using the CONVERT_TZ()
function.
Here’s how to configure named time zones in MySQL.
Continue readingFix Error Msg 8116 “Argument data type datetime2 is invalid for argument 1 of isdate function” in SQL Server
If you’re getting an error that reads Argument data type datetime2 is invalid for argument 1 of isdate function, it’s because you’re passing a datetime2 value to the ISDATE()
function, but this function doesn’t work with datetime2 values.
To fix this issue, either pass a valid date type or use the work around below to provide similar functionality that works with datetime2 values.
Continue readingHow TRY_PARSE() Works in SQL Server
In SQL Server, the TRY_PARSE()
function returns the result of an expression, translated to the requested data type, or NULL
if the conversion fails.
Basically, it works the same as the PARSE()
function, except that it returns NULL
instead of an error if the cast fails.
Both functions are intended for converting string values to either date/time or number types.
Continue readingHow PARSE() Works in SQL Server
In SQL Server, the PARSE()
function returns the result of an expression, translated to the requested data type.
Basically, it enables us to parse a string expression to the specified data type. It’s intended for converting string values to either date/time or number types.
The PARSE()
function can be handy when attempting to convert with CAST()
or CONVERT()
fails. The PARSE()
function is able to parse the expression, and this may result in certain values being converted that wouldn’t normally be able to be converted.
How to Convert Dates in SQL Server
When it comes to converting date and time values in SQL Server, things can get a little complex. But in this article I hope to demystify this topic for anyone who’s confused when it comes to making conversions between dates and other data types, as well as changing the format of date/time values, and other considerations.
Let’s jump straight in.
Continue readingAdd Minutes to a Time Value in SQLite
In SQLite, we can use the TIME()
function to add a given number of minutes to a time value.
If we’re dealing with datetime values, we can use the DATETIME()
function.
Add Minutes to a Time Value in PostgreSQL
In PostgreSQL, we can use the +
operator to add one or more minutes to a time value.
By “time” value, this could be an actual time
value, a timestamp
, or an interval
. We can also add minutes to a date
value or a date
and time
combination.
Add Hours to a Time Value in SQLite
In SQLite, we can use the TIME()
function to add a given number of hours to a time value.
If we’re dealing with datetime values, we can use the DATETIME()
function.
Subtract Seconds from a Time Value in PostgreSQL
In PostgreSQL, we can use the -
operator to subtract one or more seconds from a time value.
By “time” value, this could be an actual time
value, a timestamp
, or an interval
. We can also subtract seconds from a date
value or a date
and time
combination.