DuckDB provides us with a bunch of functions that we can use to return the current date and/or time. We can get the date in local time or coordinated universal time (UTC), depending on the function we use. These can be useful in a range of scenarios, such logging the current date in a database column, or filtering or comparing dates based on the current date.
Continue readingTag: dates
Understanding the STRPTIME() Function in DuckDB
DuckDB provides us with a good selection of date/time functions. The strptime()
function is a useful one for times where you need to convert a date string into a valid timestamp value; its sole purpose is to parse strings into timestamps.
In this article, we’ll look at how the strptime()
function works, along with some examples to demonstrate.
Fix “Error: Month out of range, expected a value between 1 and 12” when using strptime() in DuckDB
If you’re getting an error that reads “Error: Month out of range, expected a value between 1 and 12” when using the strptime()
function in DuckDB, it could be that you’re getting your months mixed up in your format string.
7 Functions that Extract the Day from a Date in DuckDB
When working with dates in DuckDB, extracting specific components like the day is a common task. DuckDB provides a good range of functions that we can use to help us to perform such a task.
This article presents seven different functions we can use to extract the day from a date in DuckDB.
Continue readingHow to Format Dates in DuckDB
When working with SQL databases such as DuckDB, dates usually conform to a specific format. In particular, when we create dates in DuckDB, they must conform to the ISO 8601 format (YYYY-MM-DD
). It’s the same with time (hh:mm:ss[.zzzzzz][+-TT[:tt]]
) and timestamp values (YYYY-MM-DD hh:mm:ss[.zzzzzzzzz][+-TT[:tt]]
).
But what if we have a requirement to present these dates or timestamps in a different format?
Fortunately, DuckDB provides us with tools to so. This article explains how to format date and timestamp values according to a specified format.
Continue readingSubtracting One or More Years from a Date in DuckDB
Sometimes we need to subtract a certain time interval from a date when working with DuckDB. We might want to subtract hours, minutes, days, months, or even years.
Below are two methods we can use to subtract one or more years from a date in DuckDB.
Continue readingList of DuckDB Format Specifiers for Date Formats
In DuckDB, we can use functions like strftime()
and strptime()
to format date or timestamp values. These functions accept a format string that specifies how the date or timestamp should be formatted.
The format string consists of one or more format specifiers. For example, '%d/%m/%Y'
is a format string that consists of three format specifiers. The output from that format specifier might look something like 05/09/2050.
2 Ways to Add Days to a Date in DuckDB
One common operation you may find yourself doing occasionally in DuckDB is adding intervals to date and/or time values. DuckDB provides us with a couple of easy ways to do this.
Here are two ways to add days to a date in DuckDB.
Continue readingUnderstanding DATE_ADD() in DuckDB
DuckDB has a date_add()
function, which allows us to add a specified time interval to a date or timestamp. This article looks at how the date_add()
function works in DuckDB, including its syntax, usage, and examples.
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.