jaikob Posted August 21, 2008 Share Posted August 21, 2008 I have set mysql to append the date to a field automatically, it adds the date in this form: "2008-06-21 21:13:09" I want to format "2008-06-21 21:13:09" to be displayed: 6-21-2008, and for another page I need that string to look like: 6/21/08 How would I achieve this? Link to comment https://forums.phpfreaks.com/topic/120782-solved-help-with-date-formatting/ Share on other sites More sharing options...
akitchin Posted August 21, 2008 Share Posted August 21, 2008 is the datetime in its own column? when pulling it from the database, look at using the DATE_FORMAT() function on the column. Link to comment https://forums.phpfreaks.com/topic/120782-solved-help-with-date-formatting/#findComment-622543 Share on other sites More sharing options...
jaikob Posted August 21, 2008 Author Share Posted August 21, 2008 that is PHP, not SQL right? Link to comment https://forums.phpfreaks.com/topic/120782-solved-help-with-date-formatting/#findComment-622548 Share on other sites More sharing options...
jaikob Posted August 21, 2008 Author Share Posted August 21, 2008 that is PHP, not SQL right? I am not finding any references in google. Link to comment https://forums.phpfreaks.com/topic/120782-solved-help-with-date-formatting/#findComment-622549 Share on other sites More sharing options...
akitchin Posted August 21, 2008 Share Posted August 21, 2008 no, that is MySQL. the reason i suggest using MySQL functions is because it takes far less work than PHP - MySQL is used to manipulating its own format. to implement it, you'd go: SELECT stuff, DATE_FORMAT(date_field, 'string according to MySQL manual') AS formatted_date FROM table formatted_date will now contain the format you're looking for. have a look in the MySQL manual under "Functions and Operators", the section for date/time functions, for a description of what that second parameter needs to look like. EDIT: linkies - http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format Link to comment https://forums.phpfreaks.com/topic/120782-solved-help-with-date-formatting/#findComment-622550 Share on other sites More sharing options...
jaikob Posted August 21, 2008 Author Share Posted August 21, 2008 Edit: duh, I forgot the colons. Thank you so much for your help! no, that is MySQL. the reason i suggest using MySQL functions is because it takes far less work than PHP - MySQL is used to manipulating its own format. to implement it, you'd go: SELECT stuff, DATE_FORMAT(date_field, 'string according to MySQL manual') AS formatted_date FROM table formatted_date will now contain the format you're looking for. have a look in the MySQL manual under "Functions and Operators", the section for date/time functions, for a description of what that second parameter needs to look like. EDIT: linkies - http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format Link to comment https://forums.phpfreaks.com/topic/120782-solved-help-with-date-formatting/#findComment-622557 Share on other sites More sharing options...
akitchin Posted August 21, 2008 Share Posted August 21, 2008 it would take a fair bit of string manipulation to format it using PHP. what did the query look like, and what error were you getting? if you're insistent on using PHP, have a look at the following functions: explode() substr() str_replace() implode() you may end up using any or all of them. Link to comment https://forums.phpfreaks.com/topic/120782-solved-help-with-date-formatting/#findComment-622560 Share on other sites More sharing options...
jaikob Posted August 21, 2008 Author Share Posted August 21, 2008 Thank you, I got it with SQL. Thanks! Link to comment https://forums.phpfreaks.com/topic/120782-solved-help-with-date-formatting/#findComment-622562 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.