TimeOnly.IsBetween(TimeOnly, TimeOnly) Method

Definition

Determines if a time falls within the range provided. Supports both "normal" ranges such as 10:00-12:00, and ranges that span midnight such as 23:00-01:00.

C#
public bool IsBetween(TimeOnly start, TimeOnly end);

Parameters

start
TimeOnly

The starting time of day, inclusive.

end
TimeOnly

The ending time of day, exclusive.

Returns

true, if the time falls within the range, false otherwise.

Remarks

If start and end are equal, this method returns false, meaning there is zero elapsed time between the two values. If you wish to treat such cases as representing one or more whole days, then first check for equality before calling this method.

Applies to

Product Versions
.NET 6, 7, 8, 9, 10