In MySQL, the TO_BASE64()
function converts a string to a base-64 encoded string and returns the result.
Tag: conversion functions
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.
STR_TO_DATE() Examples – MySQL
The MySQL STR_TO_DATE()
function allows you to build a date value from the various date parts.
When using this function, you provide a string of the various date parts, and a second argument that specifies the format that the date is provided in.
SEC_TO_TIME() Examples – MySQL
When using MySQL, you can use the SEC_TO_TIME()
function to build a time value based on a given number of seconds. Basically, you provide the number of seconds as an argument, and it will convert that to a time value.
Here’s how it works.
TO_DAYS() Examples – MySQL
In MySQL, you can use the TO_DAYS()
function to find out how many days have passed since day 0 for a particular date. For example, you can pass today’s date to this function, and it will return how many days it’s been since day 0.
This article contains examples to demonstrate.
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.
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
.
6 Ways to Convert a String to a Date/Time Value in SQL Server
If you need to convert a string into a date/time value in SQL Server, you have a number of options. In this post I outline six T-SQL functions that allow you to do this.
The six functions are:
CAST()
CONVERT()
PARSE()
TRY_CAST()
TRY_CONVERT()
TRY_PARSE()
Below are example of how you can use these functions to convert a string to a date/time data type.
How to Convert a String to a Date/Time in SQL Server using PARSE()
If you work with SQL Server, chances are you’ve used at least one of the CONVERT()
or CAST()
functions to convert from one data type to another. If you’ve ever encountered an error while trying to convert a string to a date/time data type, the PARSE()
function could be what you need.
For example, if you have a string like say, Fri, 20 Jul 2018, the CONVERT()
or CAST()
functions will throw an error. But the PARSE()
function will handle it without a problem.
The PARSE()
function returns the result of an expression, translated to the requested data type in SQL Server. So you can use it to “translate” your string value into a date/time data type (such as date, datetime, datetime2, etc).