DateTime.Now.Hour

.Hour returns the hour from the DateTime object. The results will be between 0 and 23 with midnight equal to 0, and everything after 12pm adding 12 to the hour.

Note: The .Today method does not have a time component and will always return a 0.

Applies To

Properties and Methods

None

Available

The .Hour property is available in:

  • 15.03.016
  • All newer builds

Type

Int32

Syntax

DateTime.Now.Hour;

Parameters

None

Example

var ldToday = DateTime.Today;

var ldNow = DateTime.Now;

var ldNew = new DateTime('06/10/2021 12:34:56');

Event.Form.MessageBox('Get the .Hour:' +

'\nldToday: ' + ldToday.Hour +

'\nldNow: ' + ldNow.Hour +

'\nldNew: ' + ldNew.Hour );

 

/* Expected Prompt response:

Get the .Hour:

ldToday: 0

ldNow: 9

ldNew: 12

*/