DATETIME Function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pkvasan
Forum Newbie
Posts: 4
Joined: Mon Jan 29, 2007 6:05 am

DATETIME Function

Post by pkvasan »

Hi

MySQL contains a Table with field name as Start time which is of Data Type DATETIME the Data stored in that is like 2007-01-30 14:06:00

now i want to display only Date from Date Time that is i want to display 2007-01-30 only how do i do that please help me
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Do it in the query via the DATE_FORMAT() function provided by MySQL.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

DATE_FORMAT() if possible within the MySQL query, otherwise you can extract the format using PHP after the query results are accessible.

Code: Select all

$datetime = "2007-01-30 14:06:00";
$myDate = substr($datetime, 0, 10); // 2007-01-30 (sub-string of length 10 characters from position 0)
echo $myDate;
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

MySQL DATE() function, if your mysql version supports it.
Post Reply