oavs Posted July 4, 2006 Share Posted July 4, 2006 Hi I like to now or more to the point shown how to convert my date from (2006-07-02) to 02-07-2006 on my display page.Here is the code below. Date is listed in the <td >($listed)</td>As is date is shown on the page as (2006-07-02) Thanks for your kind help.[code]function publicstats_install_addon() { } function publicstats_show_admin_icons() { } function publicstats_load_template() { $template_array = array('addon_publicstats_link', 'addon_publicstats_page'); return $template_array; } function publicstats_run_action_user_template() { switch ($_GET['action']) { case 'addon_publicstats_page': $data = publicstats_display_addon_page(); break; default: $data = ''; break; } // End switch ($_GET['action']) return $data; } function publicstats_run_action_admin_template() { switch ($_GET['action']) { case 'addon_publicstats_admin': $data = publicstats_display_admin_page(); break; default: $data = ''; break; } // End switch ($_GET['action']) return $data; } function publicstats_run_template_user_fields($tag = '') { switch ($tag) { case 'addon_publicstats_page': $data = publicstats_display_addon_page(); break; case 'addon_publicstats_link': $data = publicstats_display_addon_link(); break; default: $data = ''; break; } // End switch ($_GET['action']) return $data; } // Addon Specific Function function publicstats_display_addon_link() { $display = '<li><a href="index.php?action=addon_publicstats_page">Stats</a></li>'; return $display; } function publicstats_display_addon_page() { global $conn, $config, $lang, $count, $num_of_listings, $table_border; require_once($config['basepath'].'/include/misc.inc.php'); $misc = new misc(); // start our display in a table $display = "<table border=\"0\" width=\"100%\" id=\"table1\"> <tr> <td><u><strong>Listing Titles</strong></u> </td> <td align=\"center\"><u><strong>Seller ID</strong></u> </td> <td><u><strong>Listed On</strong></u></td> <td><u><strong>Price</strong></u> </td> <td align=\"center\"><u><strong>Viewed</strong></u> </td> </tr>"; $count = 0; $sql = "SELECT * FROM en_listingsdb WHERE listingsdb_active = 'yes' ORDER BY listingsdb_hit_count DESC LIMIT 0 , 30"; $recordSet = $conn->Execute($sql); if ($recordSet === false) { $misc->log_error($sql); } while (!$recordSet->EOF) { $id = $misc->make_db_unsafe($recordSet->fields['listingsdb_id']); $title = $misc->make_db_unsafe($recordSet->fields['listingsdb_title']); $agent = $misc->make_db_unsafe($recordSet->fields['userdb_id']); $hits = $misc->make_db_unsafe($recordSet->fields['listingsdb_hit_count']); $listed = $misc->make_db_unsafe($recordSet->fields['listingsdb_creation_date']); // Get the Price from the listingsdbelements table $sql1 = "SELECT listingsdbelements_field_value FROM ".$config['table_prefix']."listingsdbelements WHERE listingsdbelements_field_name = 'price' AND listingsdb_id = '$id'"; $recordSet1 = $conn->Execute($sql1); if ($recordSet1 === false) { $misc->log_error($sql1); } $Price = $misc->make_db_unsafe ($recordSet1->fields['listingsdbelements_field_value']); # VISABLE LINKS AND TEXT # $display .= "<tr> <td><a href=\"index.php?action=listingview&listingID=$id\">$title</a> </td> <td align=\"center\"><a href=\"index.php?action=view_user&user=$agent\">$agent</a> </td> <td >($listed)</td> <td>$ $Price</td> <td align=\"center\">($hits)</td> </tr> "; //$display .= "<a href=\"index.php?action=view_user&user=$agent\">Agent Number $agent</a> Owns The listing <a href=\"index.php?action=listingview&listingID=$id\">$title</a> has been viewed ($hits) Times<br>"; # END VISABLE LINKS AND TEXT # $recordSet->MoveNext(); } // end while $display .= "</table><br/>"; return $display; } // Addon Specific Function function publicstats_display_admin_page() { $display = 'This is a Addon page'; return $display; } ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13641-i-like-to-know-how-to-change-date-format-from-2006-07-02-to-02-07-2006/ Share on other sites More sharing options...
Orio Posted July 4, 2006 Share Posted July 4, 2006 [code=php:0]function change_date($date){$arr=explode("-",$date);$result=$arr[2]."-".$arr[1]."-".$arr[0];return $result;};[/code][hr]Orio. Quote Link to comment https://forums.phpfreaks.com/topic/13641-i-like-to-know-how-to-change-date-format-from-2006-07-02-to-02-07-2006/#findComment-52902 Share on other sites More sharing options...
oavs Posted July 7, 2006 Author Share Posted July 7, 2006 Hi Orio,thanks for your help and it's really appreciated. I am not familiar with use of functions. In order to use it, would I use the function just before the $listed = $misc->make_db_unsafe($recordSet->fields['listingsdb_creation_date']); statement ?Can you please tell me how I could use within my code please? Quote Link to comment https://forums.phpfreaks.com/topic/13641-i-like-to-know-how-to-change-date-format-from-2006-07-02-to-02-07-2006/#findComment-54606 Share on other sites More sharing options...
Crimpage Posted July 7, 2006 Share Posted July 7, 2006 No,after the $listed = $misc->make_db_unsafe($recordSet->fields['listingsdb_creation_date']); line...so $listed becomes the date, then you run the change_date function to manipulate it. Quote Link to comment https://forums.phpfreaks.com/topic/13641-i-like-to-know-how-to-change-date-format-from-2006-07-02-to-02-07-2006/#findComment-54612 Share on other sites More sharing options...
kenrbnsn Posted July 7, 2006 Share Posted July 7, 2006 You can also use a combination of the date() and strtotime() functions. In your case:[code]<?php$display .= "<tr> <td><a href=\"index.php?action=listingview&listingID=$id\">$title</a> </td> <td align=\"center\"><a href=\"index.php?action=view_user&user=$agent\">$agent</a> </td> <td>(" . date('d-m-Y',strtotime($listed)) . ")</td> <td>$ $Price</td> <td align=\"center\">($hits)</td> </tr> ";?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/13641-i-like-to-know-how-to-change-date-format-from-2006-07-02-to-02-07-2006/#findComment-54613 Share on other sites More sharing options...
oavs Posted July 8, 2006 Author Share Posted July 8, 2006 Thank you both. kenrbnsn, your code worked perfect. Thanks for doing that :-) Quote Link to comment https://forums.phpfreaks.com/topic/13641-i-like-to-know-how-to-change-date-format-from-2006-07-02-to-02-07-2006/#findComment-54655 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.