Dracolas Posted January 29, 2010 Share Posted January 29, 2010 http://www.sourcepod.com/qnayhd55-2681 How would i get it to give me the date as MM/DD/YY? TY Quote Link to comment https://forums.phpfreaks.com/topic/190264-date-formatting/ Share on other sites More sharing options...
akitchin Posted January 29, 2010 Share Posted January 29, 2010 look in the MySQL manual at the DATE_FORMAT() function, which does exactly what you're asking. a script with that few lines is not a problem to paste here, and is easier to read here than having to jump to another link. please post in the forum for small scripts like this in future. Quote Link to comment https://forums.phpfreaks.com/topic/190264-date-formatting/#findComment-1003811 Share on other sites More sharing options...
Dracolas Posted January 29, 2010 Author Share Posted January 29, 2010 ok i understand what your saying and i get the use of Date_format(), but when i go to use it on my site with date being $date which is grabbed from the database it gives me error: Warning: date_format() expects parameter 1 to be DateTime, string given in /home/a1237238/public_html/clan/home.php on line 20 what can i do to use this with the $date function... please assist Quote Link to comment https://forums.phpfreaks.com/topic/190264-date-formatting/#findComment-1003882 Share on other sites More sharing options...
akitchin Posted January 29, 2010 Share Posted January 29, 2010 you can edit this query: $result = mysql_query("SELECT * FROM wars ORDER by id DESC"); to use DATE_FORMAT() on the `date` column. what did you try? Quote Link to comment https://forums.phpfreaks.com/topic/190264-date-formatting/#findComment-1003884 Share on other sites More sharing options...
Mchl Posted January 29, 2010 Share Posted January 29, 2010 Or you can do $dateTime = new DateTime($row['date']); echo $dateTime->format('M/j/y'); Quote Link to comment https://forums.phpfreaks.com/topic/190264-date-formatting/#findComment-1003887 Share on other sites More sharing options...
salathe Posted January 29, 2010 Share Posted January 29, 2010 $dateTime->format('M/j/y'); It probably makes more sense to use m/d/y Quote Link to comment https://forums.phpfreaks.com/topic/190264-date-formatting/#findComment-1003952 Share on other sites More sharing options...
Mchl Posted January 30, 2010 Share Posted January 30, 2010 Maybe... I was writing this from top of my head... Quote Link to comment https://forums.phpfreaks.com/topic/190264-date-formatting/#findComment-1004142 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.