Below is a full list of format specifiers that can be used in format strings with functions like DATE_FORMAT()
, STR_TO_DATE()
, and FROM_UNIXTIME()
in MariaDB.
Tag: date format
How to Format the Date in MongoDB
If you have documents that store dates as Date objects, but you want to return them in a different format, you can use the $dateToString
aggregate pipeline operator.
For example, you might want a date to be returned in mm/dd/yyyy
format instead of the long ISODate()
format that includes minutes, seconds, milliseconds, etc
The $dateToString
operator converts the Date object to a string, and optionally allows you to specify a format for the resulting output.
Convert a Month Number to the Month Name in SQL Server (T-SQL)
You can use the T-SQL code below to convert a month number to its corresponding name in SQL Server.
This is for times where you don’t actually have the full date – when all you have is the month number. If you do have the date, then here’s how to get the month name from a date.
Continue readingGet the Short Day Name in SQL Server (T-SQL)
In SQL Server, you can use the FORMAT()
function to return the short day name from a date. FORMAT()
is a T-SQL function that enables you to format dates and numbers to a specified format.
This function returns its result as a string. Specifically, it returns it as either a nvarchar or null as the case may be.
Continue readingChange the Date Format For the Current Session in SQL Server
Whenever you connect to SQL Server, a bunch of default settings are applied to your session. These include the language and the date format settings.
The date format is normally determined by your default language. For example, if your default language is us_english
, then the default date format will probably be mdy
, and the first day of the week will be day 7
(Sunday).
If you change your language, you the date format will implicitly be updated accordingly.
However, you still have the option of changing the date format without changing the language. To do this, you can use SET DATEFORMAT
.
5 Ways to Get the Milliseconds from a Date in MongoDB
This article presents 5 ways to return the milliseconds portion from a Date object in MongoDB.
Continue reading5 Ways to Get the Seconds from a Date in MongoDB
This article presents 5 ways to return the seconds portion from a Date object in MongoDB.
Continue reading5 Ways to Get the Minutes from a Date in MongoDB
This article presents 5 ways to return the minutes portion from a Date object in MongoDB.
Continue reading5 Ways to Get the Hour from a Date in MongoDB
MongoDB provides a good range of aggregation pipeline operators for working with dates, including operators that extract certain parts of dates, such as the year, month, day, hours, minutes, etc.
There are also a couple of MongoDB methods that enable you to iterate through a cursor, and apply a JavaScript function. You can therefore use JavaScript to extract date values and date parts, etc from a field as required.
This article presents 5 ways to return the hour portion from a Date object in MongoDB.
Continue readingFormat sysjobhistory datetime & duration Columns in SQL Server
If you’ve ever queried the sysjobhistory
table in the msdb
database, you’ll probably know that the datetime and duration columns are stored as integers.
In particular, when you query this table, the run_date
, run_time
, and duration
columns are returned as integers, which can make it difficult to read.
Below is a query you can use to return this data in an easier to read format.
Continue reading