A Quick Look at DuckDB’s CURRENT_DATE Function

DuckDB is an in-process SQL OLAP database management system designed for analytical workloads. It is known for its speed, efficiency, and ease of use. One of the many functions DuckDB provides is current_date, which is useful for working with date-related data.

In this article, we’ll look at how the current_date function works, along with some straightforward examples.

Continue reading

Understanding Julian Day

Julian day is a concept you might occasionally encounter in SQL code or database operations, particularly when working with date and time functions. While it may seem esoteric at first, understanding Julian day can be incredibly useful for handling date calculations, especially in fields like astronomy, data analysis, and historical research.

This article looks at the origins, calculations, and practical applications of Julian day, including examples of converting between Julian day and other date formats in SQL.

Continue reading

How to Set the datestyle Variable for the Current Session in PostgreSQL

PostgreSQL has a datestyle variable that specifies the display format for date and time values, as well as the rules for interpreting ambiguous date input values. 

We can set the date/time style with the SET datestyle command, the DateStyle parameter in the postgresql.conf configuration file, or the PGDATESTYLE environment variable on the server or client.

Below is an example of using the SET datestyle command to change the datestyle for the current session.

Continue reading

Fix “The date value is less than the minimum date value allowed for the data type” When using SQL Server’s DATETRUNC() Function

If you’re getting SQL Server error msg 9837 that tells you “The date value is less than the minimum date value allowed for the data type…”, it sounds like you’re using the DATETRUNC() function with the week date part on a date that would cause the result to backtrack to a date that’s earlier than the date type supports.

This is a rare error that only occurs when using the week date part with the DATETRUNC() function on a very small number of early dates.

One way to deal with this error would be to use iso_week instead of week, if that’s suitable for your particular situation.

Continue reading