The following table lists examples of expressions that use the DatePart function to return a portion of a date or time value.
You can use these expressions in calculated controls (calculated control: A control that is used on a form, report, or data access page to display the result of an expression. The result is recalculated each time there is a change in any of the values on which the expression is based.) on forms, reports, and data access pages (data access page: A Web page, published from Access, that has a connection to a database. In a data access page, you can view, add to, edit, and manipulate the data stored in the database. A page can also include data from other sources, such as Excel.).
| Expression |
Description |
| =DatePart("yyyy", [OrderDate]) |
Displays the four-digit year of the value of the OrderDate field. |
| =DatePart("q", "12/31/2003") |
Displays the quarter the given date falls in. This expression returns 4. |
| =DatePart("h", Now()) |
Displays the hour part of the current date. The expression returns 14 if the current time is 2:08 PM. |
| =DatePart("d", Now()) | Displays the day part of the current date. The expression returns 14 if the current date is 11/14/2003. |
You can use these expressions in a calculated field in a query.
| Expression |
Description |
| YearHired: DatePart("yyyy", [HireDate]) |
Displays in the YearHired field the year each employee was hired. |
| MonthNo: DatePart("M", [OrderDate]) |
Displays in the MonthNo field the number of the month. |
Related Office Online discussions
Read related questions and answers from other Microsoft Office customers.