Reputation: 2283
I'm using symfony 2.7, I have created the API, When I submit the form(json data) using postman, It is not accepting datetime value.
Form Builder
->add('letAt','datetime')
Command
/**
* @var DateTime
* @Assert\NotNull(message="Please enter let at time.")
*/
protected $letAt;
Entity
/**
* @var \DateTime
* @ORM\Column(type="datetime", nullable=true)
*/
protected $letAt;
Request Json
{
"property_type":
{
"marketingTitle": "",
"letAt": "2018-11-11 10:10:10"
}
}
Error
"errors": {
"children": {
"marketingTitle": {},
"letAt": {
"errors": [
"This value is not valid."
],
"children": {
"date": {
"children": {
"year": {},
"month": {},
"day": {}
}
},
"time": {
"children": {
"hour": {},
"minute": {}
}
}
}
},
How can I specify dateTime value with Request?
Upvotes: 1
Views: 1327
Reputation: 2812
In Symfony 2.7 the default datetime
format is \DateTimeType::HTML5_FORMAT
and it's value yyyy-MM-dd'T'HH:mm:ssZZZZZ
.
You specify your format type like that:
->add('letAt','datetime', array('format' => 'yyyy-MM-dd HH:mm:ss', 'widget' => 'single_text'))
Upvotes: 3