Formatted Date
Get formatted dates from date/timestamp fields.
This adds a formatted
field to all date or timestamp fields. Also contains support for the daterange
field type.
Schema
Extension
graphql
graphql
extend type FieldItemTypeDaterange {
startDate(format: String, drupalDateFormat: DrupalDateFormat): String!
endDate(format: String, drupalDateFormat: DrupalDateFormat): String!
}
Example with Drupal Format
Use the drupalDateFormat
argument with the name of the Drupal date format:
graphql
query {
entityById(entityType: NODE, id: 5) {
... on Node {
fieldDate {
formatted(drupalDateFormat: HTML_DATETIME)
}
}
}
}
Example with PHP Format
Use the format
argument if you want to provide the datetime.format yourself:
graphql
query {
entityById(entityType: NODE, id: 5) {
... on Node {
fieldDate {
formatted(format: "Y")
}
}
}
}