Jump to content

Archived

This topic is now archived and is closed to further replies.

oavs

I like to know how to change date format from (2006-07-02) to 02-07-2006

Recommended Posts

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]

Share this post


Link to post
Share on other sites
[code=php:0]function change_date($date){
$arr=explode("-",$date);
$result=$arr[2]."-".$arr[1]."-".$arr[0];
return $result;
};[/code]
[hr]

Orio.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Thank you both.

kenrbnsn, your code worked perfect. Thanks for doing that :-)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.