Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8712735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:10:15+00:00 2026-06-13T05:10:15+00:00

My Entity: /** * @var \DateTime $publishedAt * * @ORM\Column(name=published_at, type=date) * * @Assert\Date()

  • 0

My Entity:

/**
 * @var \DateTime $publishedAt
 *
 * @ORM\Column(name="published_at", type="date")
 * 
 * @Assert\Date()
 */
private $publishedAt;

/**
 * Set publishedAt
 *
 * @param \DateTime $publishedAt
 * @return MagazineIssue
 */
public function setPublishedAt(\DateTime $publishedAt)
{
    $this->publishedAt = $publishedAt;

    return $this;
}

/**
 * Get published_at
 *
 * @return \DateTime 
 */
public function getPublishedAt()
{
    return $this->publishedAt;
}

My form builder:

$builder->add('publishedAt');

My view:

{{ form_widget(form) }}

When I select the date in the selects and submit the form I catche the error:

Catchable Fatal Error: Argument 1 passed to ... must be an instance of DateTime, 
string given, called in .../vendor/symfony/symfony/src/Symfony/Component/Form
/Util/PropertyPath.php on line 537 and defined in ... line 214 

Why it happens? If I replace the field setter with public function setPublishedAt($publishedAt) I got the error:

Fatal error: Call to a member function format() on a non-object 
in .../vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/DateType.php on line 44 

If I change the form builder to

 $builder->add('publishedAt','date')

all works fine. Why it happens? Why symfony can’t guess it and pass to field setter the proper date format (\DateTime instead of string)?

EDIT: if I remove the @Assert\Date() then all works fine too. I think it’s a sf2.1 bug with guessing the date field type

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:10:16+00:00Added an answer on June 13, 2026 at 5:10 am

    To solve this problem you can

    1.change the assert from @Assert\Date() to @Assert\Type('\DateTime')

    OR

    2.change the form builder to $builder->add('publishedAt','date')

    OR

    3.specify the input option in the form builder: $builder->add('publishedAt',null,array('input' => 'datetime'))

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

@Entity @Table(name=Product_info) public class Product { private int ProductIndex; private int priority; private Date
I'm trying to compare date values in entity framework. DateTime selectedDate = Calendar1.SelectedDate; var
@Entity public class TestClass implements Serializable{ private Integer id; private Set<String> mySet; @Id @GeneratedValue
@Entity public class Blobx { private String name; private BlobKey blobKey; @Id @GeneratedValue(strategy =
Can I set a private property via reflection? public abstract class Entity { private
I have a simple LINQ query on ADO.NET Entity Framework as follows var result
@Entity @Table(name = BOOKTEST) @NamedQueries({@NamedQuery(name = Booktest.findAll, query = SELECT b FROM Booktest b),
Possible Duplicate: The entity cannot be constructed in a LINQ to Entities query var
I have a list of a very simply entity, which has a nullable DateTime
I have this entity (Registro): <?php namespace Gitek\RegistroBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** *

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.