phpretard Posted August 1, 2009 Share Posted August 1, 2009 I am trying to display the date like - 08-01-2009 by calling a function with a var. I know the code below is wrong but it's what I'm working with. <?php function myDate($startdate){ echo "The date is ". $startdate; $startdate="2009-08-01 07:27:40"; $predate=explode(' ', $startdate); $splitdate=explode('-', $predate[0]); $redeemDate="$splitdate[1]-$splitdate[2]-$splitdate[0]"; $new_date="$startdate"; } myDate($new_date); ?> Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/168389-solved-date-funtion/ Share on other sites More sharing options...
JonathanV Posted August 1, 2009 Share Posted August 1, 2009 http://be2.php.net/manual/en/function.date.php That's gonna be a better way to do it + there's a lot of examples you can see there Quote Link to comment https://forums.phpfreaks.com/topic/168389-solved-date-funtion/#findComment-888249 Share on other sites More sharing options...
GingerRobot Posted August 1, 2009 Share Posted August 1, 2009 Or, if you're timestamp is coming from a database, you can do it directly in the query: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format Quote Link to comment https://forums.phpfreaks.com/topic/168389-solved-date-funtion/#findComment-888250 Share on other sites More sharing options...
phpretard Posted August 1, 2009 Author Share Posted August 1, 2009 Or, if you're timestamp is coming from a database, you can do it directly in the query: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format TIGHT!!! So if I have a date in the DB as: 2009-08-01 07:27:40 I am not sure how to use it like this... GET_FORMAT(DATE,'USA') '%m.%d.%Y' select date from table ??? Quote Link to comment https://forums.phpfreaks.com/topic/168389-solved-date-funtion/#findComment-888251 Share on other sites More sharing options...
phpretard Posted August 1, 2009 Author Share Posted August 1, 2009 Got it! function myDate($table){ connect(); $the_date=mysql_query("select date from $table"); while ($date=mysql_fetch_assoc($the_date)) { $startdate=$date['date']; }mysql_free_result($the_date); $predate=explode(' ', $startdate); $splitdate=explode('-', $predate[0]); $readDate="$splitdate[1]-$splitdate[2]-$splitdate[0]"; $new_date="$readDate"; echo $new_date; } myDate("categories"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/168389-solved-date-funtion/#findComment-888255 Share on other sites More sharing options...
phpretard Posted August 1, 2009 Author Share Posted August 1, 2009 Here it is used in a different function: function cat_tr(){ connect(); $get_cat = mysql_query("select * from categories order by cat_name"); while ($cat=mysql_fetch_assoc($get_cat)) { echo" <tr> <td>".$cat['cat_name']."</td> <td><a href=\"javascript:void(0)\"><img border=\"0\" alt=\"Edit ".$cat['cat_name']."\" src=\"images/b_edit.png\" width=\"16\" height=\"16\"></a></td> <td><a href=\"javascript:void(0)\"><img border=\"0\" alt=\"Delete ".$cat['cat_name']."\" src=\"images/b_drop.png\" width=\"16\" height=\"16\"></a></td> <td>";myDate("categories");echo"</td> </tr> "; } mysql_free_result($get_cat); } Quote Link to comment https://forums.phpfreaks.com/topic/168389-solved-date-funtion/#findComment-888256 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.