5 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 reading

Format 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