wayjo Posted August 21, 2008 Share Posted August 21, 2008 Hi folks, I am a bit of a newbie with PHP and MySQL but I am thoroughly enjoying it. I have a dilemma which I am sure is only so because of my own ignorance. here's the problem... I have a database that basically helps manage a list of tasks. When I write a new task to the task_master table I automatically use the MySQL DATETIME field format, eg "YYYY-MM-DD HH:MM:SS". Now, I do want all this information but I do not want to display (initially) all of it, I just want the "YYYY-MM-DD" part, equivalent to MySQLs DATE format. I am trying to find a date function in PHP that will take the MySQL stored date and time and allow me to just echo the year, month and day. Should I not use the MySQL format and just use PHP to create a date/time it will understand an stick it in text field or can I do both? I get a feeling I am missing something really obvious so please accept my apologies in advance. Darn newbies, nothing but a nuisance ! Thanks in advance for any assistance that can be offered. cheers wayjo Link to comment https://forums.phpfreaks.com/topic/120704-date-formatting-between-php-and-mysql/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 21, 2008 Share Posted August 21, 2008 The mysql DATE() function will return just the date part of a DATETIME field. Link to comment https://forums.phpfreaks.com/topic/120704-date-formatting-between-php-and-mysql/#findComment-621961 Share on other sites More sharing options...
abdfahim Posted August 21, 2008 Share Posted August 21, 2008 what I understand is you need the following function echo Date ("Y-m-d", strtotime($thisdate)); // $thisdate is the datetime you read from your database. Link to comment https://forums.phpfreaks.com/topic/120704-date-formatting-between-php-and-mysql/#findComment-621964 Share on other sites More sharing options...
giraffemedia Posted August 21, 2008 Share Posted August 21, 2008 You can do that just by using DATE_FORMAT in your MYSQL query wayjo. something like... $query = "SELECT *, DATE_FORMAT(followup, '%D %b %Y') AS followup FROM contacts WHERE contacts_id = $record"; You want this part (where followup is the name of your datetime column in mysql) - DATE_FORMAT(followup, '%D %b %Y') AS followup If you want to view all the different ways of formatting have a look at http://www.dan.co.uk/mysql-date-format/ Regards James Link to comment https://forums.phpfreaks.com/topic/120704-date-formatting-between-php-and-mysql/#findComment-621973 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.