In MariaDB, you can use the DATE_FORMAT()
function to return various date parts from a date. One of the things you can return is the short day name. For example Tue
or Wed
(instead of Tuesday
or Wednesday
).
Tag: how to
3 Ways to Convert a String to a Date in MongoDB
If you have a MongoDB collection with dates stored as strings, you can convert those into the Date BSON type if required.
Below are three ways to convert a string into a Date in MongoDB.
Continue readingReturn the Current Workstation Name that’s Connected to SQL Server (T-SQL)
Occasionally you might find yourself in the situation where you need to get the name of the current workstation that’s connected to SQL Server.
For example, maybe you have a stored procedure that inserts data, and you want to record the name of the workstation that inserted the data.
In such cases, you can use the HOST_NAME()
function.
This is not to be confused with getting the server name.
Continue readingRemove Duplicates when using $unionWith in MongoDB
In MongoDB, the $unionWith
aggregation pipeline stage performs a union of two collections, and it includes duplicates.
This behaves in a similar way to SQL’s UNION ALL
, which also includes duplicates. By contrast, using just UNION
(i.e. without the ALL
)in SQL removes duplicates.
In MongoDB, we don’t have the option of specifying $unionWith ALL
or similar, so we need to reduce duplicates in another way.
In MongoDB, we can remove duplicates by using the $group
stage.
Change the Time Zone Offset on a datetimeoffset Value in SQL Server (T-SQL)
You can use the SWITCHOFFSET()
function in SQL Server to change the time zone offset on a datetimeoffset value.
The function accepts two arguments; a datetimeoffset(n) value (or an expression that can be resolved to a datetimeoffset(n) value), and the new time zone.
Continue reading3 Ways to Return a Random Sample of Documents from a MongoDB Collection
If you need to return a small sample of random documents from a collection, here are three approaches you can try using the aggregation pipeline.
Continue readingSET SQLBLANKLINES: How to Allow Blank Lines in SQLcl & SQL*Plus
If you’re trying to run a multi-line query in SQLcl or SQL*Plus, and you keep getting an error such as “Unknown Command”, but running it in SQL Developer causes no such error, maybe this post will help.
By default, SQLcl and SQL*Plus don’t allow blank lines in SQL statements. However, you can change this with the SET SQLBLANKLINES
command.
4 Functions to Get the Hour from a Time Value in MariaDB
Below are 4 functions that enable you to return the hour from a time value in MariaDB.
Continue readingReplace Multiple Characters in a String in SQL Server (T-SQL)
In SQL Server, the REPLACE()
function enables us to replace a string with another string. But what if you want to replace a list of characters with another list of characters?
The TRANSLATE()
function might help.
2 Ways to Unhide an Index in MongoDB
If you have a hidden index in MongoDB, you can use the unhideIndex()
method or the collMod
administration command to unhide it.