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

  • Home
  • SEARCH
  • 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 6862125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:37:23+00:00 2026-05-27T02:37:23+00:00

Short Version: Does anyone know how to do a simple date insert using Doctrine2?

  • 0

Short Version:

Does anyone know how to do a simple date insert using Doctrine2? I need to insert a date in the format YYYY-MM-DD (‘Y-m-d’) into a MySQL ‘date’ field.

If you already know how to do this, you can probably skip the explanation below of what I’ve tried so far. Otherwise, more details about my problem follow below the break.


Long Version:

I have a Doctrine2 CRUD application and need to insert a form-submitted date into a MySQL database.

The date is submitted in a form using three dropdown menus: Year, Month, and Day.

In my Doctrine repository method, I use date() to convert the submitted values into a date and then invoke a method named setCreated() in my entity class:

$string = $values['year'] . '-' . $values['month'] . '-' . $values['day'];
$date = date('Y-m-d', strtotime($string));
$item->setCreated($date);

Then in setCreated(), first I tried to pass in the date like this:

public function setCreated($date) {
    $this->created = $date;
}

But that gives me this error message: “Call to a member function format() on a non-object in …Doctrine\DBAL\Types\DateType.php”.

Next I tried altering the setter like this:

public function setCreated($date) {
    $this->published = new \Doctrine\DBAL\Types\DateType($date);
}

But this doesn’t work either: “Call to private Doctrine\DBAL\Types\Type::__construct()…”

Finally I tried creating a simple Date object to insert:

public function setCreated($date) {
    $this->created = new \Date($date);
}

That gives me this error: “Class ‘Date’ not found in Path\To\Entity\Item.php…”

I also tried the above version without the leading backslash for Date, which gives me this error: “Warning: require(Path\Entity\Date.php) failed to open stream. No such file or directory in Path\Doctrine\Common\ClassLoader.php…”

(To confirm, my include paths are configured properly in php.ini — specifically the include_path \php\PEAR which is where Date.php is located.)

There’s an explanation in the Doctrine manual about working with DateTime instances, but I don’t need to store the time, just the date as YYYY-MM-DD.

This seems like it would be a pretty common issue – does anyone see what I’m doing wrong and/or know how to do a date insert in Doctrine2?

  • 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-05-27T02:37:23+00:00Added an answer on May 27, 2026 at 2:37 am

    You care too much about your database. Just create the DateTime instance and assign it as value to the object property which is of type DateTime.

    The database will store it as you have defined it, so no worries.

    And if you format it back to a YYYY-MM-DD formatted string value, you will see it did store.

    Doctrine is to abstract away from your concrete database, so don’t worry so much about your database when you use it.

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

Sidebar

Related Questions

Short Version: Does anyone know of a way --inside a SQL 2000 trigger-- of
Does anyone know how to set the date format for the Team - History
Does anyone out there know if its possible to show a working version of
Short Version: When I've created a Channel using ChannelFactory on a client which uses
Short Version I have a list of int s that I need to figure
Does anyone know if it possible to define the equivalent of a java custom
Short Version : I'm using a 64bit dll (system.data.sqlite) in an Asp.net MVC app
I can't find this information online or in the documentation, does anyone know what
Short version: I want to trigger the Form_Load() event without making the form visible.
Short version: I'm wondering if it's possible, and how best, to utilise CPU specific

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.