Date & Date and Time
The Date and Date and Time fields are used to make it possible for an editor to select a date or date and time when creating an item (Figure 1.1).
When adding this item field to an item type you can set a default value under Data > Default Value in the item field settings. Accepted vallues are ‘Now’ or DD/MM/YYYY.
In frontend you can then retrieve the DateTime object via the GetDateTime()-method and work with it as per normal:
RAZOR
@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel>
<h3>Date Fields</h3>
@{
var datefield = Model.Item.GetDateTime("Date");
var datetimefield = Model.Item.GetDateTime("DateTime");
}
<table class="table table-striped">
<tr>
<th>Field</th>
<th>Value</th>
<th>Comments</th>
</tr>
<!--Date-->
<tr>
<td>Date</td>
<td>
Date: @datefield.Date <br />
DayOfYear: @datefield.DayOfYear <br>
DayOfWeek: @datefield.DayOfWeek
</td>
<td></td>
</tr>
<!--DateTime-->
<tr>
<td>DateTime</td>
<td>
Date: @datetimefield.Date <br />
DayOfYear: @datetimefield.DayOfYear <br>
DayOfWeek: @datetimefield.DayOfWeek <br />
TimeOfDay: @datetimefield.TimeOfDay <br />
ShortDateString: @datetimefield.ToShortDateString()
</td>
<td></td>
</tr>
</table>