Reputation: 6251
I have an event page that displays events from database. In my database, I have a column with datetime format. is there a way to only get the date or time separate from each other in a select to be displayed in PHP ?
Note : I am looking for anything default/core PHP function for this issue.
Upvotes: 4
Views: 11025
Reputation: 147
date_format Method used for splitting date and time.
SELECT
date_format(ColumnName, '%Y-%m-%d') as Date,
date_format(ColumnName, '%H:%i:%s') as Time
FROM
tableName;
Upvotes: 0
Reputation: 282
Use this query , you will get your desired output :
$sql = "SELECT DATE(datecolumn) as mydate, TIME(datecolumn) as mytime FROM `tablename`";
Upvotes: 9
Reputation: 12117
You can use date_format
function
SELECT date_format(dateCol, '%Y-%m-%d') as `date`,
date_format(dateCol, '%H:%i:%s') as `time` FROM tableName;
Upvotes: 2
Reputation: 4715
Just use the mysql functions:
SELECT DATE(column), TIME(column) FROM table
On php-side use date('d.m.y', $column)
and date('H:i:s', $column)
.
Upvotes: 1