[#BloombergLP-bdlt-Datetime-validateAndSetDatetime]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlt.adoc[bdlt]::xref:BloombergLP/bdlt/Datetime.adoc[Datetime]::validateAndSetDatetime
: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
validateAndSetDatetime(
    int year,
    int month,
    int day,
    int hour = 0,
    int minute = 0,
    int second = 0,
    int millisecond = 0);
----

== Description

Set the &quot;date&quot; part of this object&apos;s value to the specified `year`, `month`, and `day`, and the &quot;time&quot; part to the optionally specified `hour`, `minute`, `second`, and `millisecond`, if they represent a valid `Datetime` value, with trailing fields that are not specified set to 0&period; Return 0 on success, and a non&hyphen;zero value (with no effect) otherwise&period;

DEPRECATED&colon; Use `setDatetimeIfValid` instead&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)
|===


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