Jump to content


Photo

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


  • Please log in to reply
5 replies to this topic

#1 oavs

oavs
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts
  • LocationDownunder

Posted 04 July 2006 - 02:33 PM

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.

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;
    }
     
?>


#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 04 July 2006 - 02:40 PM

function change_date($date){
$arr=explode("-",$date);
$result=$arr[2]."-".$arr[1]."-".$arr[0];
return $result;
};
 

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 oavs

oavs
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts
  • LocationDownunder

Posted 07 July 2006 - 11:29 PM

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?

#4 Crimpage

Crimpage
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts
  • LocationBrisbane, Australia

Posted 07 July 2006 - 11:42 PM

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.

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 07 July 2006 - 11:44 PM

You can also use a combination of the date() and strtotime() functions. In your case:
<?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>
		";?>

Ken

#6 oavs

oavs
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts
  • LocationDownunder

Posted 08 July 2006 - 02:35 AM

Thank you both.

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users