Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2: How to operate with datetime-objects

i can't really get it how to work with datetime-objects in symfony2.

i have few games-entries in database which one has a datetime-property. and now i want to compare to the actual date: i want to have all records from the past 10 days. how can i achieve this?

i tried this

date($game->getZeit(), mktime(0,0,0,date('m'),date('d'),date('y')))

to get a compareable date which i can compare with

date('Y.m.d H:i:s', mktime(0,0,0,date('m'),date('d'),date('y')));

but that didnt work because

$game->getZeit()

cannot be converted to a string. why? so how can i debug this one? how can i know its value? how can i compare it with other datetimes or date-strings?

quick help would be really appreciated! :)

kind regards

like image 842
Fabian Avatar asked Oct 30 '12 10:10

Fabian


1 Answers

In Symfony2 (Doctrine ORM) dates represented as DateTime objects (http://php.net/DateTime) So if $game->getZeit() is instance of DateTime, you can convert it to string like

$game->getZeit()->format('Y-m-d H:i:s');
like image 157
olegkhuss Avatar answered Nov 15 '22 08:11

olegkhuss