You can use the date operator in OCL when you need the calendar-date portion of a DateTime value and do not want its time of day to affect the result.
What date returns
date returns the date portion of a DateTime value. The returned value has its time component set to 00:00:00.
For example, if Orderdate contains a date and time, applying .date removes the time portion:
Order.allinstances->first.Orderdate.date
If the first order's Orderdate is 2026-01-08 14:35:00, the expression returns 2026-01-08 00:00:00.
Syntax
Apply .date to a DateTime expression:
<DateTime expression>.date
To extract the date from the current system date and time, apply it to DateTime.Now:
DateTime.Now.date
Use date for calendar-date comparisons
DateTime values can differ because of their time components even when they occur on the same calendar day. Apply .date when the comparison is about the day rather than the exact time.
For example, this expression compares the order's calendar date with today's calendar date:
self.Orderdate.date = DateTime.Now.date
Use this pattern when an order recorded at 09:00:00 and the current time is 16:00:00 should both be treated as occurring today.
Related date and time operations
| Need | Operation |
|---|---|
| Keep only the time-of-day portion of the current DateTime | time |
| Test whether a date is within a start and end date | inDateRange |
| Convert a string to a date value and extract its date portion | strToDate |
| Safely parse a date/time string, returning null for invalid input | tryParse |
| Format a date or time for display | formatDateTime |
