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

This `struct` provides a namespace for utility functions that provide non&hyphen;primitive operations on dates&period;

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
struct DateUtil;
----

== Static Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdlt/DateUtil/addMonths.adoc[`addMonths`] 
| Return the date that is the specified `numMonths` from the specified `original` date, adjusted as necessary according to the specified `eomFlag` (end&hyphen;of&hyphen;month flag)&period; If `eomFlag` is `true` and `original` is the last day of the month, then adjust the result to be the last day of the month&semi; if `eomFlag` is `false`, then no such adjustment is performed&period; In any case, if the day of the month in `original` does not exist in the month of the result (e&period;g&period;, February 29, 2001), move the resulting date to the last day of the month&period; The behavior is undefined unless the operation results in a valid `Date` value&period; Note that `numMonths` may be negative&period;
| xref:BloombergLP/bdlt/DateUtil/addMonthsEom.adoc[`addMonthsEom`] 
| Return the date that is the specified `numMonths` from the specified `original` date, adjusted as necessary according to the following (end&hyphen;of&hyphen;month) rules&colon; (1) if `original` is the last day of a month, adjust the result to be the last day of the month, and (2) if the day of the month in `original` does not exist in the month of the result (e&period;g&period;, February 30), move the resulting date to the last day of the month&period; The behavior is undefined unless the operation results in a valid `Date` value&period; Note that `numMonths` may be negative&period;
| xref:BloombergLP/bdlt/DateUtil/addMonthsNoEom.adoc[`addMonthsNoEom`] 
| Return the date that is the specified `numMonths` from the specified `original` date, adjusted as necessary according to the following (non&hyphen;end&hyphen;of&hyphen;month) rule&colon; if the day of the month in `original` does not exist in the month of the result (e&period;g&period;, February 29, 2001), move the resulting date to the last day of the month&period; The behavior is undefined unless the operation results in a valid `Date` value&period; Note that `numMonths` may be negative&period;
| xref:BloombergLP/bdlt/DateUtil/addYears.adoc[`addYears`] 
| Return the date that is the specified `numYears` from the specified `original` date, adjusted as necessary according to the specified `eomFlag` (end&hyphen;of&hyphen;month flag)&period; If `eomFlag` is `true` and `original` is the last day of the month, then adjust the result to be the last day of the month&semi; if `eomFlag` is `false`, then no such adjustment is performed&period; In any case, if the day of the month in `original` does not exist in the month of the result (e&period;g&period;, February 29, 2001), move the resulting date to the last day of the month&period; The behavior is undefined unless the operation results in a valid `Date` value&period; Note that `numYears` may be negative&period;
| xref:BloombergLP/bdlt/DateUtil/addYearsEom.adoc[`addYearsEom`] 
| Return the date that is the specified `numYears` from the specified `original` date, adjusted as necessary according to the following (end&hyphen;of&hyphen;month) rules&colon; (1) if `original` is the last day of a month, adjust the result to be the last day of the month, and (2) if the day of the month in `original` does not exist in the month of the result (e&period;g&period;, February 29, 2001), move the resulting date to the last day of the month&period; The behavior is undefined unless the operation results in a valid `Date` value&period; Note that `numYears` may be negative&period;
| xref:BloombergLP/bdlt/DateUtil/addYearsNoEom.adoc[`addYearsNoEom`] 
| Return the date that is the specified `numYears` from the specified `original` date, adjusted as necessary according to the following (non&hyphen;end&hyphen;of&hyphen;month) rule&colon; if the day of the month in `original` does not exist in the month of the result (e&period;g&period;, February 30), move the resulting date to the last day of the month&period; The behavior is undefined unless the operation results in a valid `Date` value&period; Note that `numYears` may be negative&period;
| xref:BloombergLP/bdlt/DateUtil/convertFromYYYYMMDD.adoc[`convertFromYYYYMMDD`] 
| Load, into the specified `result`, the `Date` value represented by the specified `yyyymmddValue` in the &quot;YYYYMMDD&quot; format&period; Return 0 on success, and a non&hyphen;zero value, with no effect on `result`, if `yyyymmddValue` does not represent a valid `Date`&period;
| xref:BloombergLP/bdlt/DateUtil/convertFromYYYYMMDDRaw.adoc[`convertFromYYYYMMDDRaw`] 
| Return the `Date` value represented by the specified `yyyymmddValue` in the &quot;YYYYMMDD&quot; format&period; The behavior is undefined unless `yyyymmddValue` represents a valid `Date`&period;
| xref:BloombergLP/bdlt/DateUtil/convertToYYYYMMDD.adoc[`convertToYYYYMMDD`] 
| Return the integer value in the &quot;YYYYMMDD&quot; format that represents the specified `date`&period;
| xref:BloombergLP/bdlt/DateUtil/earliestDayOfWeekInMonth.adoc[`earliestDayOfWeekInMonth`] 
| Return the earliest date in the specified `month` of the specified `year` that falls on the specified `dayOfWeek`&period; The behavior is undefined unless `1 &lt;&equals; year &lt;&equals; 9999` and `1 &lt;&equals; month &lt;&equals; 12`&period;
| xref:BloombergLP/bdlt/DateUtil/fromYmd.adoc[`fromYmd`] 
| Return an `optional` having a `Date` with the specified `year`, `month`, and `day`, if those form a valid `Date` (see `Date&colon;&colon;isValid`)&semi; otherwise return an `optional` without a value&period;
| xref:BloombergLP/bdlt/DateUtil/isValidYYYYMMDD.adoc[`isValidYYYYMMDD`] 
| Return `true` if the specified `yyyymmddValue` represents a valid `Date` value in the &quot;YYYYMMDD&quot; format, and `false` otherwise&period;
| xref:BloombergLP/bdlt/DateUtil/lastDayInMonth.adoc[`lastDayInMonth`] 
| Return the latest date in the specified `month` of the specified `year`&period; The behavior is undefined unless `1 &lt;&equals; year &lt;&equals; 9999` and `1 &lt;&equals; month &lt;&equals; 12`&period;
| xref:BloombergLP/bdlt/DateUtil/lastDayOfWeekInMonth.adoc[`lastDayOfWeekInMonth`] 
| Return the latest date in the specified `month` of the specified `year` that falls on the specified `dayOfWeek`&period; The behavior is undefined unless `1 &lt;&equals; year &lt;&equals; 9999` and `1 &lt;&equals; month &lt;&equals; 12`&period;
| xref:BloombergLP/bdlt/DateUtil/nextDayOfWeek.adoc[`nextDayOfWeek`] 
| Return the first date _after_ the specified `date` that falls on the specified `dayOfWeek`&period; The behavior is undefined unless the resulting date is no later than 9999&sol;12&sol;31&period;
| xref:BloombergLP/bdlt/DateUtil/nextDayOfWeekInclusive.adoc[`nextDayOfWeekInclusive`] 
| Return the first date _on_ or _after_ the specified `date` that falls on the specified `dayOfWeek`&period; The behavior is undefined unless the resulting date is no later than 9999&sol;12&sol;31&period;
| xref:BloombergLP/bdlt/DateUtil/nthDayOfWeekInMonth.adoc[`nthDayOfWeekInMonth`] 
| 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;
| xref:BloombergLP/bdlt/DateUtil/previousDayOfWeek.adoc[`previousDayOfWeek`] 
| Return the last date _before_ the specified `date` that falls on the specified `dayOfWeek`&period; The behavior is undefined unless the resulting date is no earlier than 1&sol;1&sol;1&period;
| xref:BloombergLP/bdlt/DateUtil/previousDayOfWeekInclusive.adoc[`previousDayOfWeekInclusive`] 
| Return the last date _on_ or _before_ the specified `date` that falls on the specified `dayOfWeek`&period; The behavior is undefined unless the resulting date is no earlier than 1&sol;1&sol;1&period;
|===



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