How 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 reading

How 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.

Continue reading

How to Format the Month in Roman Numerals in Oracle

Oracle Database provides us with the ability to return the month from a date using roman numerals.

For example, if the month is August, its decimal value would be 08 and it’s roman numeral equivalent would be VIII.

The way to do this is to use the RM or rm format element in your format mask. That will format the month using roman numerals in uppercase or lowercase respectively.

Specifying the date format can be done in several places.

Continue reading

How to Remove the Right Padding on the Day Name in Oracle

In Oracle Database, when using the TO_CHAR() function to return the day name from a date, padding will be appended to the day name if it’s shorter than the longest valid day name for the given language and calendar.

Well, that’s the default behaviour. However, you can change this if you wish.

To suppress this padding, all you need to do is prepend the day name format element with fm.

Continue reading

How to Return the Day Number with a Suffix in MariaDB

MariaDB includes a large collection of date and time functions that return a given date in a certain format.

One thing you can do is return the day number with the relevant “st/nd/rd/th” suffix. For example, instead of returning it as say, 10 July 2025, it’s returned as 10th July 2025.

Below is an example of adding the relevant suffix to a day number in MariaDB.

Continue reading

Add the Ordinal Indicator to a Date in Oracle

In Oracle Database, we can use the TH format element to add the ordinal number suffix to the result of a TO_CHAR() operation when formatting dates.

For example, instead of outputting 10 Feb we could output 10th Feb. Or, instead of outputting 21 century, we can output 21st century. The same applies for spelled date components. For example, instead of Twenty One, we can output Twenty First.

Continue reading

How to Spell Out the Year when Formatting a Date in Oracle

Oracle Database includes a good selection of datetime format elements. that enable us to format dates and times when using the TO_CHAR(datetime) function.

One of these (the YEAR format element) allows us to format a date with the year spelled out. For example, instead of 1972, we’d get NINETEEN SEVENTY-TWO.

We can also use SYEAR so that BC dates are prefixed with a minus sign (-).

Continue reading