I am pulling the value EventDate from a table called events. At the moment is giving me a timestamp along with the date - 2012-05-29 00:00:00.
Is there anyway to trim this in PHP?
Try using MySQL's build in functions such as DATE_FORMAT()
or even DATE()
SELECT
DATE_FORMAT(EventDate, '%Y-%m-%d') AS eventDate
FROM events;
SELECT
DATE(EventDate) AS eventDate
FROM events;
If don't want to store time stamp in DB,then change field type from datetime to date.Then while retrieving you will get only date.
OR
$date = //store DB date in this variable;
date('Y-m-d',strtotime($date));
If you really need to do this in PHP, use the date()
function.
$date = '2012-05-29 00:00:00';
echo date('Y-m-d', strtotime($date)); // 2012-05-29
SELECT eventDate FROM events
, doSELECT DATE(eventDate) FROM events
.