ldoozer Posted November 28, 2006 Share Posted November 28, 2006 Hi all, can anyone tell me the best way to only display the date in the output of a datetime mysql field.So I have 2006-11-28 20:54:46 stored but only want to display 2006-11-28. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted November 28, 2006 Share Posted November 28, 2006 [CODE]<?php$date = '2006-11-28 20:54:46';list($year,$time) = explode(" ",$date);echo $year;?>[/CODE] Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted November 28, 2006 Share Posted November 28, 2006 Alternatively you can tell MySQL to return only that part of the field and avoid modifying it in PHP altogether. Quote Link to comment Share on other sites More sharing options...
ldoozer Posted November 28, 2006 Author Share Posted November 28, 2006 how would i do that? (embarrased) Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted November 28, 2006 Share Posted November 28, 2006 http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.htmlDATE([i]expr[/i])SELECT DATE('2003-12-31 01:02:03')So if you have a table [i]the_table[/i] and the DATETIME column is named [i]the_date[/i]:SELECT *, DATE(the_date) AS the_date_disp FROM the_table WHERE 1Also, if you want to format the date like you can with PHP's date function, you'll want to look up DATE_FORMAT in MySQL.SELECT * DATE_FORMAT(the_date, '%a. %b. %D, %Y') AS the_date_disp FROM the_table WHERE 1Hope that helps. Quote Link to comment Share on other sites More sharing options...
ldoozer Posted November 30, 2006 Author Share Posted November 30, 2006 Thanks very much for all the help. :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.