Advertisement:

Author Topic: How to show time of any posted item  (Read 9187 times)

mkmobi

  • Full Member
  • ***
  • Posts: 119
How to show time of any posted item
« on: July 06, 2013, 06:14:29 pm »
I have a php code for showing time
any one can convert it for osclass 3.1.2, bcute


Code: [Select]
<?php
function ago($time)
{
   
$periods = array("second""minute""hour""day""week""month""year""decade");
   
$lengths = array("60","60","24","7","4.35","12","10");

   
$now time();

       
$difference     $now $time;
       
$tense         "ago";

   for(
$j 0$difference >= $lengths[$j] && $j count($lengths)-1$j++) {
       
$difference /= $lengths[$j];
   }

   
$difference round($difference);

   if(
$difference != 1) {
       
$periods[$j].= "s";
   }

   return 
"$difference $periods[$j] 'ago' ";
}
?>

TheDeadLives

  • Sr. Member
  • ****
  • Posts: 279
Re: How to show time of any posted item
« Reply #1 on: July 06, 2013, 06:18:39 pm »
I have one code. If the item was posted today, it will show today. If it was posted yesterday it will show yesterday, etc. It is working in osclass 3.1.2

Code: [Select]
<?php

$date 
osc_item_field("dt_pub_date");
$yesterday 172800;
$today 86400;
$time strtotime($date);
$time time()-$time;

if (
$today $time) {echo '<b>Today</b>';}
else if (
$yesterday $time && $yesterday $today) {echo '<b>Yesterday</b>';}
else if (
$time$yesterday) {echo osc_format_date(osc_item_pub_date());}

?>
« Last Edit: July 06, 2013, 09:45:35 pm by TheDeadLives »

crudis08

  • Newbie
  • *
  • Posts: 23
Re: How to show time of any posted item
« Reply #2 on: July 06, 2013, 07:34:00 pm »
I have one code. If the item was posted today, it will show today. If it was posted yesterday it will show yesterday, etc. It is working in osclass 3.1.2

Code: [Select]
<?php

$date 
osc_item_field("dt_pub_date");
$yesterday 172800;
$today 86400;
$time strtotime($date);
$time time()-$time;

if (
$today $time) {echo 'Today';}
else if (
$yesterday $time && $yesterday $today) {echo 'Yesterday';}

?>


Where to put the code to display it?

TheDeadLives

  • Sr. Member
  • ****
  • Posts: 279
Re: How to show time of any posted item
« Reply #3 on: July 06, 2013, 08:16:09 pm »
I have one code. If the item was posted today, it will show today. If it was posted yesterday it will show yesterday, etc. It is working in osclass 3.1.2

Code: [Select]
<?php

$date 
osc_item_field("dt_pub_date");
$yesterday 172800;
$today 86400;
$time strtotime($date);
$time time()-$time;

if (
$today $time) {echo '<b>Today</b>';}
else if (
$yesterday $time && $yesterday $today) {echo '<b>Yesterday</b>';}
else if (
$time$yesterday) {echo osc_format_date(osc_item_pub_date());}

?>


Where to put the code to display it?

You can put wherever you want. To appear in the categories you put in search_list.php or search_gallery.php. To appear in the item, you put in item.php
« Last Edit: July 06, 2013, 09:45:51 pm by TheDeadLives »

crudis08

  • Newbie
  • *
  • Posts: 23
Re: How to show time of any posted item
« Reply #4 on: July 06, 2013, 08:22:32 pm »
Quote
You can put wherever you want. To appear in the categories you put in search_list.php or search_gallery.php. To appear in the item, you put in item.php

Not working. Nothing appears.

TheDeadLives

  • Sr. Member
  • ****
  • Posts: 279
Re: How to show time of any posted item
« Reply #5 on: July 06, 2013, 09:43:27 pm »
Quote
You can put wherever you want. To appear in the categories you put in search_list.php or search_gallery.php. To appear in the item, you put in item.php

Not working. Nothing appears.

That's because none of your ads is from today or yesterday. I put the wrong code too. The code is this:

Code: [Select]
<?php

$date 
osc_item_field("dt_pub_date");
$yesterday 172800;
$today 86400;
$time strtotime($date);
$time time()-$time;

if (
$today $time) {echo '<b>Today</b>';}
else if (
$yesterday $time && $yesterday $today) {echo '<b>Yesterday</b>';}
else if (
$time$yesterday) {echo osc_format_date(osc_item_pub_date());}

?>

This works for none premium ads. For premium ads you need to change osc_item_pub_date() for osc_premium_pub_date().

Sorry for my mistake, put this one and everything works!  ;D
« Last Edit: July 06, 2013, 09:45:11 pm by TheDeadLives »

fog

  • Hero Member
  • *****
  • Posts: 1062
Re: How to show time of any posted item
« Reply #6 on: July 06, 2013, 11:02:47 pm »
Hello, what are the numbers: 172800 and 86400?
Are not seconds! How can I put in seconds? Needed to put more variables: two days, three days, one week, etc..
Thanks  :)

TheDeadLives

  • Sr. Member
  • ****
  • Posts: 279
Re: How to show time of any posted item
« Reply #7 on: July 06, 2013, 11:14:56 pm »
Hello, what are the numbers: 172800 and 86400?
Are not seconds! How can I put in seconds? Needed to put more variables: two days, three days, one week, etc..
Thanks  :)

@fog, those numbers are seconds. The number 86400 is the number of seconds that a day has (60x60x24). 172800 is the number of seconds that 2 days have. To add 3 days, etc, you just need to calculate the total seconds that the period of time that you want have, make a new variable and make a new else if with echo.

I hope that i have helped u  :D  ;)

fog

  • Hero Member
  • *****
  • Posts: 1062
Re: How to show time of any posted item
« Reply #8 on: July 07, 2013, 12:26:55 am »
You're quite right ... I was wrong in my accounts  ???  ;D
thank you

Of course you helped, ... I will now work on this.
« Last Edit: July 07, 2013, 12:32:04 am by fog »

TheDeadLives

  • Sr. Member
  • ****
  • Posts: 279
Re: How to show time of any posted item
« Reply #9 on: July 07, 2013, 12:30:13 am »
No problem  ;D  ;)

mkmobi

  • Full Member
  • ***
  • Posts: 119
Re: How to show time of any posted item
« Reply #10 on: July 07, 2013, 05:06:07 pm »
thanks guys for your reply
but how to show result like
Posted Today at  06:35 PM

crudis08

  • Newbie
  • *
  • Posts: 23
Re: How to show time of any posted item
« Reply #11 on: July 07, 2013, 05:13:54 pm »
Quote
You can put wherever you want. To appear in the categories you put in search_list.php or search_gallery.php. To appear in the item, you put in item.php

Not working. Nothing appears.

That's because none of your ads is from today or yesterday. I put the wrong code too. The code is this:

Code: [Select]
<?php

$date 
osc_item_field("dt_pub_date");
$yesterday 172800;
$today 86400;
$time strtotime($date);
$time time()-$time;

if (
$today $time) {echo '<b>Today</b>';}
else if (
$yesterday $time && $yesterday $today) {echo '<b>Yesterday</b>';}
else if (
$time$yesterday) {echo osc_format_date(osc_item_pub_date());}

?>

This works for none premium ads. For premium ads you need to change osc_item_pub_date() for osc_premium_pub_date().

Sorry for my mistake, put this one and everything works!  ;D

Works perfect!! can display and time? (Today - 12:49)

mkmobi

  • Full Member
  • ***
  • Posts: 119
Re: How to show time of any posted item
« Reply #12 on: July 07, 2013, 05:24:27 pm »
thanks crudis08 but i think it is 24 hour clock
but how to show AM / PM
for example : Posted Today at 05:23:07 PM
« Last Edit: July 07, 2013, 05:28:06 pm by mkmobi »

crudis08

  • Newbie
  • *
  • Posts: 23
Re: How to show time of any posted item
« Reply #13 on: July 07, 2013, 05:44:20 pm »
thanks crudis08 but i think it is 24 hour clock
but how to show AM / PM
for example : Posted Today at 05:23:07 PM

Yes, can display it?

TheDeadLives

  • Sr. Member
  • ****
  • Posts: 279
Re: How to show time of any posted item
« Reply #14 on: July 07, 2013, 06:36:27 pm »
thanks crudis08 but i think it is 24 hour clock
but how to show AM / PM
for example : Posted Today at 05:23:07 PM

Quote
Yes, can display it?

You could search the forum  :-\  ;D.

The answer is in here http://forums.osclass.org/general-help/bug-of-not/

Add this code to functions.php, in your theme:

Code: [Select]
<?php
function cust_format_date_with_time($date$dateformat null) {
    if(
$dateformat==null) {
        
$dateformat osc_date_format();
    }
    
$ampm = array('AM' => __('AM'), 'PM' => __('PM'), 'am' => __('am'), 'pm' => __('pm'));

    
$time strtotime($date);
    
$dateformat preg_replace('|(?<!\\\)A|'osc_escape_string($ampm[date('A'$time)]), $dateformat);
    
$dateformat preg_replace('|(?<!\\\)a|'osc_escape_string($ampm[date('a'$time)]), $dateformat);

    return 
date(osc_time_format(), $time);
?>

In your search_list.php/search_gallery.php add this code:

Code: [Select]
<?php echo cust_format_date_with_time(osc_item_pub_date()); ?>
Now you have the hour. To modify the format of the hour go to show more->settings->general.

That is all!  ;D