acumatica Creating Date and Time Fields in Acumatica The PX(DB)DateAttribute Attribute


Example

The PXDBDate attribute and the PXDate attribute are designed to work with a DAC field of the Nullable<DateTime> (DateTime?) type and store date value with an optional time part inside a single field. Wheather PX(DB)DateAttribute should save time in addition to date in a DAC field is defined by the PreserveTime property: when PreserveTime is set to True, the time part of a field value is preserved, otherwise only the date part is saved in a DAC field:

#region UsrDateTime
public abstract class usrDateTime : IBqlField
{ }

[PXDBDate(PreserveTime = true, InputMask = "g")]
[PXUIField(DisplayName = "DateTime Value")]
public DateTime? UsrDateTime { get; set; }
#endregion

#region UsrDate
public abstract class usrDate : IBqlField
{ }

[PXDBDate]
[PXUIField(DisplayName = "Date Value")]
public DateTime? UsrDate { get; set; }
#endregion

In the UI, for a field decorated with PXDBDateAttribute or PXDateAttribute the system creates an input control accepting either only date values or both date and time values depending on the value of PreserveTime property. This concept works exactly the same on a form:

enter image description here

<px:PXDateTimeEdit runat="server" ID="edUsrDateTime" DataField="UsrDateTime" Size="SM" />
<px:PXDateTimeEdit runat="server" ID="edUsrDate" DataField="UsrDate" />

and within a grid cell:

enter image description here

<Columns>
    ...
    <px:PXGridColumn DataField="UsrDateTime" Width="130px" />
    <px:PXGridColumn DataField="UsrDate" Width="90px" />
    ...
</Columns>