date
date is Python's built-in datetime.date class, exposed inside the formula sandbox as a constructor. Calling it returns a date object representing a calendar date (year, month, day) without a time component. Use date() for date comparisons, date arithmetic, and when constructing date values for filter conditions.
Syntax
date(year, month, day)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| year | int | Yes | The year (e.g., 2024) |
| month | int | Yes | The month (1–12) |
| day | int | Yes | The day of the month (1–31) |
Returns
Type: date
A date object representing the specified calendar date.
Class Methods
| Method | Description | Example |
|---|---|---|
date.today() |
Returns today's date | date.today() |
Instance Methods and Properties
| Method/Property | Description | Example |
|---|---|---|
.year |
The year | date.today().year |
.month |
The month | date.today().month |
.day |
The day | date.today().day |
.isoformat() |
ISO 8601 string (YYYY-MM-DD) | date.today().isoformat() |
.strftime(fmt) |
Format as string | date.today().strftime('%d/%m/%Y') |
.weekday() |
Day of week (0=Monday, 6=Sunday) | date.today().weekday() |
.isoweekday() |
Day of week (1=Monday, 7=Sunday) | date.today().isoweekday() |
.replace(...) |
Return date with replaced fields | date.today().replace(day=1) |
Examples
Create a specific date:
date(2024, 6, 15)
Get today's date:
date.today()
Calculate 90 days ago:
date.today() - timedelta(days=90)
Get the first day of the current month:
date.today().replace(day=1)
Format a date for display:
date.today().strftime('%B %d, %Y')
Produces a string like 'June 15, 2024'.
Compare dates:
date(2024, 6, 15) > date(2024, 1, 1)
Returns True.
Using date() in Filter Conditions
When building standard filter conditions that compare against date fields, use the date() function to construct date values:
date.today() - timedelta(days=30)
This ensures the value is a proper date object that PB can translate into the source system's date format. Avoid passing raw date strings — use date() or datetime() constructors instead.
Notes
- Date arithmetic uses
timedelta— see timedelta. - For date and time combined, use datetime.
- Dates support comparison operators:
<,>,<=,>=,==,!=. - Subtracting two dates produces a
timedeltaobject.
Related Documentation
- datetime — Date and time combined
- timedelta — Duration for date arithmetic
- Working with Types — Overview of all data types
- Formulas in Filters — Using date() in filter conditions
Comments
0 comments
Please sign in to leave a comment.