In DuckDB, the strftime() function is a handy tool for formatting date and timestamp values as strings. It accepts the date/timestamp value and a format string as arguments. The function then returns the date/time in the format provided by the format string.
date functions
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.
Understanding 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.
An Overview of the DATE_SUBTRACT() Function in PostgreSQL
PostgreSQL 16 introduced the date_subtract() function that allows us to subtract an interval from a timestamp with time zone.
It computes times of day and daylight-savings adjustments according to the time zone named by the third argument, or the current TimeZone setting if that is omitted.
PostgreSQL DATE_ADD() Function Explained
PostgreSQL 16 introduced the date_add() function that allows us to add an interval to a timestamp with time zone.
It computes times of day and daylight-savings adjustments according to the time zone named by the third argument, or the current TimeZone setting if that is omitted.
Understanding the DATE_BUCKET() Function in SQL Server
The release of SQL Server 2022 came with the introduction of the DATE_BUCKET() function.
The DATE_BUCKET() function allows us to arrange data into groups that represent fixed intervals of time. It returns the date/time value that corresponds to the start of each date/time bucket, as defined by the arguments passed to the function.
An Introduction to the DATETRUNC() Function in SQL Server
In SQL Server, we can use the DATETRUNC() function to truncate a date/time value to a specified precision.
For example, we could use it to truncate a date value like 2024-10-25 to 2024-01-01, or a time value like 10:35:12 to 10:00:00.
The DATETRUNC() function was introduced in SQL Server 2022 (16.x).
7 Functions that Separate Hours, Minutes, Seconds, & Microseconds from a Time Value in MySQL
Below are seven functions we can use to extract the hours, minutes, seconds, and microseconds from a time value in MySQL.
Three ISDATE() Alternatives that Work with DATETIME2 Values in SQL Server
SQL Server’s ISDATE() function checks whether or not an expression is a valid date. However, you may be aware that this function doesn’t work on datetime2 values. On datetime2 values it returns 0, which means it’s not a valid date, even when the value is a valid date.
This is obviously not ideal, because the datetime2 type is a valid date type. Microsoft even recommends that we use datetime2 instead of datetime for our dates, as it aligns with the SQL Standard and it provides more fractional seconds precision.
Anyway, below are three options we can use to check whether a datetime2 value is a valid date.