DateField
DateField
DateField describes a date field in a content type or global field schema, with data_type set to isodate. It adds a start date and an end date to the properties of Field.
When to Use This Class: Use this class for a date value such as a publish date or an event date.
Conceptual Role: Acts as the Field subclass that the SDK creates for a field with data_type set to isodate.
Returns: DateField. A date field of a schema.
Properties
DateField inherits every property of Field and adds the properties below.
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| StartDate | string? | No | null | Earliest date the field accepts. Serialized as startDate. |
| EndDate | string? | No | null | Latest date the field accepts. Serialized as endDate. |
Class-Level Notes
Date values.
- StartDate and EndDate are strings. The SDK sends them as you set them and does not check their format.
- The JSON keys use camel case (startDate, endDate), unlike the other keys of a field.
Method Index
DateField has no methods. Set its properties and add it to ContentModelling.Schema.
Class-Level Snippet
The snippet below creates a content type with a mandatory publish date field.
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Models.Fields;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
ContentModelling model = new ContentModelling
{
Title = "Blog Post",
Uid = "blog_post",
Schema = new List<Field>
{
new TextboxField { DisplayName = "Title", Uid = "title", DataType = "text", Mandatory = true, Unique = true },
new DateField { DisplayName = "Publish Date", Uid = "publish_date", DataType = "isodate", Mandatory = true }
}
};
try
{
ContentstackResponse response = client.Stack("<API_KEY>").ContentType().Create(model);
Console.WriteLine(response.OpenJsonObjectResponse()["notice"]);
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}