Examples of Converting ‘date’ to ‘datetime2’ in SQL Server (T-SQL)

This article contains examples of converting a date value to a datetime2 value in SQL Server.

When you convert a date value to datetime2, extra information is added to the value. This is because the datetime2 data type contains both date and time information. The date data type, on the other hand, only contains date information.

The datetime2 data type is basically an extension of the datetime data type. It has a larger date range, a larger default fractional precision, and optional user-specified precision.

In any case, the conversion process is exactly the same regardless of the data type. The only difference is the amount of information that’s available between date, datetime and datetime2.

Continue reading

Examples of Converting ‘date’ to ‘datetime’ in SQL Server (T-SQL)

This article contains examples of converting a date value to a datetime value in SQL Server.

When you convert a date value to datetime, extra information is added to the value. This is because the datetime data type contains both date and time information. The date data type, on the other hand, only contains date information.

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.

Continue reading

PARSE() vs CAST() vs CONVERT() in SQL Server: What’s the Difference?

Perhaps you’ve encountered the T-SQL PARSE(), CAST(), and CONVERT() functions when working with SQL Server and wondered what the difference is. All three functions seem to do the same thing, but there are subtle differences between them.

In this article I aim to outline the main differences between these functions.

Continue reading

PARSE() vs TRY_PARSE() in SQL Server: What’s the Difference?

In SQL Server, the PARSE() and TRY_PARSE() functions are used for translating a value into another data type. They essentially do the same thing, with one exception; how they deal with errors.

If PARSE() fails when attempting to parsing to a different data type, it will return an error. If TRY_PARSE() fails, it will return NULL.

Continue reading