---
title: "date(bySettingHour:minute:second:of:matchingPolicy:repeatedTimePolicy:direction:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/calendar/date(bysettinghour:minute:second:of:matchingpolicy:repeatedtimepolicy:direction:)"
---

# date(bySettingHour:minute:second:of:matchingPolicy:repeatedTimePolicy:direction:)

Returns a new Date representing the date calculated by setting hour, minute, and second to a given time on a specified Date.

## Declaration

```swift
func date(bySettingHour hour: Int, minute: Int, second: Int, of date: Date, matchingPolicy: Calendar.MatchingPolicy = .nextTime, repeatedTimePolicy: Calendar.RepeatedTimePolicy = .first, direction: Calendar.SearchDirection = .forward) -> Date?
```

## Parameters

- `hour`: A specified hour.
- `minute`: A specified minute.
- `second`: A specified second.
- `date`: The date to start calculation with.
- `matchingPolicy`: Specifies the technique the search algorithm uses to find results. Default value is .nextTime.
- `repeatedTimePolicy`: Specifies the behavior when multiple matches are found. Default value is .first.
- `direction`: Specifies the direction in time to search. Default is .forward.

## Return Value

Return Value A Date representing the result of the search, or nil if a result could not be found.

## Discussion

Discussion If no such time exists, the next available time is returned (which could, for example, be in a different day than the nominal target date). The intent is to return a date on the same day as the original date argument.  This may result in a date which is backward than the given date, of course.

## See Also

### Calculating Dates from Components

- [date(from:)](foundation/calendar/date(from:).md)
- [date(byAdding:to:wrappingComponents:)](foundation/calendar/date(byadding:to:wrappingcomponents:).md)
- [date(byAdding:value:to:wrappingComponents:)](foundation/calendar/date(byadding:value:to:wrappingcomponents:).md)
- [date(bySetting:value:of:)](foundation/calendar/date(bysetting:value:of:).md)
