Extract part of existing date values using a calculated field

Extract part of existing date values using a calculated field

  1. In query Design view, create a query. Add the tables whose records you want to use.

  2. Use the DatePart function in an expression in an empty cell in the Field row in the query design grid.

    The syntax for this function is:

    DatePart(datepart,date)

    The datepart argument is the abbreviation for the part of the date you want returned. Examples are "yyyy" for a four-digit year and "q" for a calendar quarter. The date argument is either a field name with the Date/Time data type or a literal date such as "7-Nov-93".

    The following table lists examples of expressions that apply the DatePart function to the OrderDate field from the Orders table.

    If the value in
    OrderDate is

    This expression

    Returns
    3-Jun-93 DatePart("m",[OrderDate]) 6 (month of year)
    28-Mar-92 DatePart("yyyy",[OrderDate]) 1992 (four-digit number of year)
  3. Add any other fields you want to include in the query to the query design grid.