[#BloombergLP-bdlt-DateUtil-nthDayOfWeekInMonth]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlt.adoc[bdlt]::xref:BloombergLP/bdlt/DateUtil.adoc[DateUtil]::nthDayOfWeekInMonth
:relfileprefix: ../../../
:mrdocs:

Return the `n`th `dayOfWeek` in the given month and year&period;

== Synopsis

Declared in `&lt;bdlt&lowbar;dateutil&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
static
xref:BloombergLP/bdlt/Date.adoc[Date]
nthDayOfWeekInMonth(
    int year,
    int month,
    xref:BloombergLP/bdlt/DayOfWeek/Enum.adoc[DayOfWeek::Enum] dayOfWeek,
    int n);
----

== Description

Return the date in the specified `month` of the specified `year` corresponding to the specified `n`th occurrence of the specified `dayOfWeek`&period; If `n &lt; 0`, return the date corresponding to the `&hyphen;n`th occurrence of the `dayOfWeek` counting from the end of the `month` towards the first of the `month`&period; If `5 &equals;&equals; n` and a result cannot be found in `month`, then return the date of the first `dayOfWeek` in the following month&period; If `&hyphen;5 &equals;&equals; n` and a result cannot be found in `month`, then return the date of the last `dayOfWeek` in the previous month&period; The behavior is undefined unless `1 &lt;&equals; year &lt;&equals; 9999`, `1 &lt;&equals; month &lt;&equals; 12`, `n !&equals; 0`, `&hyphen;5 &lt;&equals; n &lt;&equals; 5`, and the resulting date is neither earlier than 0001&sol;01&sol;01 nor later than 9999&sol;12&sol;31&period;

For example&colon; &grave; nthDayOfWeekInMonth(2004, 11, DayOfWeek&colon;&colon;e&lowbar;THURSDAY, 4)&semi; &grave; returns November 25, 2004, the fourth Thursday in November, 2004&period;

== Return Value

matching date

== Parameters

[cols="1,4"]
|===
| Name| Description
| *year*
| calendar year
| *month*
| month of year in `&lsqb;1 &period;&period; 12&rsqb;`
| *dayOfWeek*
| desired day of week
| *n*
| which occurrence to select (non&hyphen;zero&semi; negative counts from end)
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
