From MongoDB 4.0, you can use the $toInt
aggregation pipeline operator to convert a value to an integer.
Tag: convert
MongoDB $toDouble
From MongoDB 4.0, you can use the $toDouble
aggregation pipeline operator to convert a value to a double.
MongoDB $toDecimal
From MongoDB 4.0, you can use the $toDecimal
aggregation pipeline operator to convert a value to a decimal.
MongoDB $toBool
From MongoDB 4.0, you can use the $toBool
aggregation pipeline operator to convert a value to a boolean.
MongoDB $toString
From MongoDB 4.0, you can use the $toString
aggregation pipeline operator to convert a value to a string.
MongoDB $convert
In MongoDB, you can use the $convert
aggregation pipeline operator to convert a value to a specified type.
You can convert any valid expression to a double, string, ObjectId, boolean, Date, integer, long, or decimal.
Continue readingConverting Between Date & Time Data Types in SQL Server (T-SQL Examples)
When you convert between date and time data types in SQL Server, you need to be mindful of how the new data type will handle the value you’re trying to assign to it.
In some cases you might lose part of the value, in other cases you might gain a bunch of zeros (increasing storage size in the process). You may also end up with a value that’s been rounded up.
The following articles contain examples of conversions between the different date and time data types, with a particular focus on the issues I just mentioned.
Convert ‘datetimeoffset’ to ‘time’ in SQL Server (T-SQL Examples)
If you have a datetimeoffset value, but you don’t need the date and time zone offset part, converting it to time will save you a lot of storage space (while removing unnecessary details from the value). This article contains examples of converting a datetimeoffset value to a time value in SQL Server.
Convert ‘datetimeoffset’ to ‘date’ in SQL Server (T-SQL Examples)
If you have a datetimeoffset value, but you don’t need the time and time zone offset part, converting it to date will save you a lot of storage space (while removing unnecessary details from the value). This article contains examples of converting a datetimeoffset value to a date value in SQL Server.
Convert ‘datetimeoffset’ to ‘smalldatetime’ in SQL Server (T-SQL Examples)
This article contains examples of converting a datetimeoffset value to smalldatetime in SQL Server.
When you convert a datetimeoffset value to smalldatetime, the date and hours are copied. The minutes are rounded up (depending on the seconds value) and the seconds are set to 0.