I have premiere_poland column in database table which is date type.
/** @Column(type="date", nullable=TRUE) */
protected $premiere_poland;
My issue is, that I want to store dates like 2012-01-01, 2013-00-00, 2013-01-00 etc. and I want that type of dates, but Doctrine every time returns that column data in DateTime instance and the true form is changed (for ex. 2013-01-00 = 31.12.2012).
How can I make Doctrine to return this value as a string, not DateTime class instance.
My query:
$q = "SELECT
g,
p.name AS platform_name, p.name_short AS platform_name_short, p.id AS platform_id,
s.premiere_poland, s.premiere_world
FROM Game g
JOIN g.genres ge
JOIN g.platform p
LEFT JOIN g.specification s
WHERE g.id = :id";
$results = $db->createQuery($q)->setParameter('id', $_GET['id'])->getResult();
I would suggest to create two columns, one for a date (of type
DateTime/DATE) and another that would indicate what parts of date (day, month, year) should be taken into account when displaying a premiere date (of typeSETor a bit mask).Function that displays a premiere date could look like this:
Of course this function shouldn’t be placed whitin an entity object – it’d be too complex (especially if we take i18n and i10l into account) and “unrelated” to the entity.
This techinque should let you show following dates:
12-06-2012,Game::SHOW_DATE),01-01-2015,Game::SHOW_YEAR),01-03-2012,Game::SHOW_MONTH),01-06-2012,Game::SHOW_SEASON), Winter, 2010 (01-12-2010,Game::SHOW_SEASON)