JPA Criteria Query Date/Time Extraction
Jakarta Persistence criteria queries use the following interfaces and enums to extract temporal components like year, month, or hour from date and time values.
TemporalField # Base interface
├─ LocalDateField # Enum for Date fields
├─ LocalTimeField # Enum for Time fields
└─ LocalDateTimeField # Enum for DateTime fields Date and Time components
To extract a date or time component in a criteria query specify the enum value that represents that component as the first argument of CriteriaBuilder.extract(TemporalField, Expression)jakarta.persistence.criteria.CriteriaBuilder.extract(TemporalField,Expression)Create an expression that returns the value of a field extracted from a date, time, or datetime.
The base interface for all temporal component types, represented by the following enums.
Defines the component types of Date values (such as java.time.LocalDate, and java.sql.Date), including YEAR, MONTH, DAY, DAY_OF_WEEK, and DAY_OF_YEAR.
Defines the component types of Time values (such as java.time.LocalTime, and java.sql.Time), including HOUR, MINUTE, and SECOND.
Defines component types applicable to DateTime/Timestamp values (e.g., java.time.LocalDateTime, java.sql.Timestamp), combining options from the two component type list above.