[#BloombergLP-bdlt-Datetime-setDatetimeIfValid-0b]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlt.adoc[bdlt]::xref:BloombergLP/bdlt/Datetime.adoc[Datetime]::setDatetimeIfValid
:relfileprefix: ../../../
:mrdocs:

Set this object from calendar fields if they form a valid datetime&period;

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
int
setDatetimeIfValid(
    int year,
    int month,
    int day,
    int hour = 0,
    int minute = 0,
    int second = 0,
    int millisecond = 0,
    int microsecond = 0);
----

== Description

Set the &quot;date&quot; part of this object to have the value represented by the specified `year`, `month`, and `day` attributes, and set the &quot;time&quot; part to have the value represented by the optionally specified `hour`, `minute`, `second`, `millisecond`, and `microsecond` attributes, if the eight attribute values (collectively) represent a valid `Datetime` value (see `isValid`)&period; Unspecified trailing optional parameters default to 0&period; Return 0 on success, and a non&hyphen;zero value (with no effect) otherwise&period;

== Return Value

0 on success, and a non&hyphen;zero value otherwise

== Parameters

[cols="1,4"]
|===
| Name| Description
| *year*
| year attribute
| *month*
| month attribute
| *day*
| day&hyphen;of&hyphen;month attribute
| *hour*
| hour attribute (default 0)
| *minute*
| minute attribute (default 0)
| *second*
| second attribute (default 0)
| *millisecond*
| millisecond attribute (default 0)
| *microsecond*
| microsecond attribute (default 0)
|===


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