showing "posted X days ago"

Discuss news styles, css code, and other Coranto customizations in here...the possibilities are endless, so have at it!

Moderator: Spunkmeyer

showing "posted X days ago"

Postby nuggetman » Mon Oct 13, 2003 3:54 am

Is there away that next to the time in newsposts I could put how many days ago it was posted?

IE: This is a subject (posted 10/10/03 by nuggetman [2 days ago])
nuggetman
 
Posts: 78
Joined: Sun May 19, 2002 9:15 pm

Postby Zygor » Mon Oct 13, 2003 7:48 am

the post would have to be built for every view or every day, not a smart move for a big site
Zygor
I drop by now and again.
User avatar
Zygor
 
Posts: 498
Joined: Sun Nov 03, 2002 3:40 am
Location: Adelaide, Australia

Postby Sumaleth » Mon Oct 13, 2003 7:54 am

You could do it with some PHP code in the page itself. Put the date value into the post as a PHP variable and do some calculations based on the current date at time of viewing.
Sumaleth
 
Posts: 1366
Joined: Thu Jul 11, 2002 4:31 pm

Postby Parahead » Mon Oct 13, 2003 4:43 pm

I don´t have the answer to your question right now, but just saw Sumaleth´s answer about adding PHP and couldn´t help butting in. Why messing around with different languages when Coranto admits a user to use Perl? ;-)

Anyway, there are a variable you can use in your style called $newstime which contains the time when the news was created. There also are some *nix-methods and also Coranto-methods to handle dates.

For example, I have a style to show a NEW-image if the post is less then 30 days old.
Code: Select all
<PerlCode>
$consider_new = time() - (30 * (60*60*24));
if ($newstime > $consider_new){
</PerlCode>
 <IMG SRC="/images/new.gif" WIDT="30" HEIGTH="15">
<PerlCode>
}
</PerlCode>


I know it is not the solution to your problem, just wanted to show you an example of handling dates, I can dig into this later to give you a more specific answer. Don´t know how much Perl you know, maybe this gave you some hints?
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby Parahead » Mon Oct 13, 2003 6:45 pm

This litle codesnip does what you want, just put it in your style where you want the number to show.
Code: Select all
<PerlCode>
$newshtml .= int ((time() - $newstime)/86400);
</PerlCode>
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby LoneOwl » Mon Oct 13, 2003 8:37 pm

That only works for regular builds. If you don't do a build at least once a day it won't work.
User avatar
LoneOwl
 
Posts: 1465
Joined: Sun Mar 10, 2002 2:57 am
Location: That one place, you know?

Postby Zexion_ » Tue Oct 14, 2003 7:38 pm

rebuilding every day would kind of suck UNLESS you also have phpBB or vbulletin comments on your articles in which case you WANT to build at least once per day (at 3am :-) )

If you dont want to have to build everyday, I would do it with javascript With something like this:
http://javascript.internet.com/calculat ... -long.html

Then just have conranto enter the date into the date var and remove the input boxes. There are plenty of free javascript code out there to calculate age or time elapsed...
Time flies like an arrow, fruit flies like a banana.
User avatar
Zexion_
 
Posts: 260
Joined: Tue Sep 03, 2002 8:23 pm

Postby AeroSoul » Tue Oct 14, 2003 9:56 pm

place at the top of your page, between <head> and </head> tags:
Code: Select all
<script language="javascript>function difference(oldtime) {
   var nowtime = new Date();
   var milliseconds1 = oldtime.getTime();
   var milliseconds2 = nowtime.getTime();
   var difference = milliseconds2 - milliseconds1;
   var daysDifference = Math.floor(difference/1000/60/60/24);
   difference = difference - daysDifference*1000*60*60*24
   var hoursDifference = Math.floor(difference/1000/60/60);
   difference = difference - hoursDifference*1000*60*60
   var minutesDifference = Math.floor(difference/1000/60);
   difference = difference - minutesDifference*1000*60
   var secondsDifference = Math.floor(difference/1000);
   document.write('This topic is ' + daysDifference + ' days, ' + hoursDifference + ' hours, ' + minutesDifference + ' minutes, ' + secondsDifference + ' and seconds old.');
}
</script>
place this in your news style where you want the days since thing to go:
Code: Select all
<PerlCode>$JSMonth = $TwoDigitMonth--;</PerlCode><script language="javascript">
difference(new Date(<Field: Year>,<Field: JSMonth>,<Field: Day>,<Field: TwoDigitHour>,<Field: Minute>,<Field: Second>));</script>
haven't tested it yet, and i think someone with more javascript knowledge should optimize it more.
Keep the dream alive!
User avatar
AeroSoul
 
Posts: 562
Joined: Sat Mar 09, 2002 10:30 pm
Location: Toronto, Canada

Postby AndyP » Sat May 28, 2005 8:00 am

I found this and got it working but I was wondering how I could have it so that the 'posted XX hours ago' only appears IF the number of hours was (for example) less than 6 hours ? Is that possible using <IF> statements ?
AndyP
 
Posts: 165
Joined: Wed Jan 10, 2007 10:10 pm

Postby AndyP » Sat May 28, 2005 8:01 am

*Double post" :(
AndyP
 
Posts: 165
Joined: Wed Jan 10, 2007 10:10 pm

Postby InSAnE NiNjA » Sat May 28, 2005 8:26 am

Code: Select all
<script language="javascript>function diff(oldtime) {
   var nowtime = new Date();
   var milliseconds1 = oldtime.getTime();
   var milliseconds2 = nowtime.getTime();
   var diff = milliseconds2 - milliseconds1;
   var daysDiff = Math.floor(diff/1000/60/60/24);
   diff = diff - daysDiff*1000*60*60*24
   var hoursDiff = Math.floor(diff/1000/60/60);
   document.write('This topic is '
   + (daysDiff>0 ? daysDiff + ' days': '')
   + (daysDiff<1 && hoursDiff>6 ? hoursDiff + ' hours': '')
   + ' old.');
}
</script>


i'm tired but with that..
after 6 hours it will display hours up to 23, after 1 day it will only display days.

just a rewrite and shortening..
..nuttier then a squirrel turd..
User avatar
InSAnE NiNjA
 
Posts: 1213
Joined: Sat Jan 25, 2003 6:35 am

Postby AndyP » Sat May 28, 2005 9:43 am

That didn't seem to work but maybe part of the code that goes inside the style needs to be altered as well...

InSAnE NiNjA wrote:
Code: Select all
<script language="javascript>function diff(oldtime) {
   var nowtime = new Date();
   var milliseconds1 = oldtime.getTime();
   var milliseconds2 = nowtime.getTime();
   var diff = milliseconds2 - milliseconds1;
   var daysDiff = Math.floor(diff/1000/60/60/24);
   diff = diff - daysDiff*1000*60*60*24
   var hoursDiff = Math.floor(diff/1000/60/60);
   document.write('This topic is '
   + (daysDiff>0 ? daysDiff + ' days': '')
   + (daysDiff<1 && hoursDiff>6 ? hoursDiff + ' hours': '')
   + ' old.');
}
</script>


i'm tired but with that..
after 6 hours it will display hours up to 23, after 1 day it will only display days.

just a rewrite and shortening..
Last edited by AndyP on Sat May 28, 2005 9:52 am, edited 1 time in total.
AndyP
 
Posts: 165
Joined: Wed Jan 10, 2007 10:10 pm

Postby InSAnE NiNjA » Sat May 28, 2005 9:50 am

Code: Select all
<script language="javascript>function difference(oldtime) {
   var nowtime = new Date();
   var milliseconds1 = oldtime.getTime();
   var milliseconds2 = nowtime.getTime();
   var difference = milliseconds2 - milliseconds1;
   var daysDifference = Math.floor(difference/1000/60/60/24);
   difference = difference - daysDifference*1000*60*60*24
   var hoursDifference = Math.floor(difference/1000/60/60);
   difference = difference - hoursDifference*1000*60*60
   var minutesDifference = Math.floor(difference/1000/60);
   difference = difference - minutesDifference*1000*60
   var secondsDifference = Math.floor(difference/1000);
//   document.write('This topic is ' + daysDifference + ' days, ' + hoursDifference + ' hours, ' + minutesDifference + ' minutes, and ' + secondsDifference + ' seconds old.');

if (daysDifference > 1 && hoursDifference > 6)
   document.write('This topic is ' hoursDifference + ' hours, and ' + minutesDifference + ' minutes old.');
}
</script>


there ya go
..nuttier then a squirrel turd..
User avatar
InSAnE NiNjA
 
Posts: 1213
Joined: Sat Jan 25, 2003 6:35 am

Postby AndyP » Sat May 28, 2005 11:35 am

Okay well I decided to do this but it doesn't quite work perfectly...

Code: Select all
<script language="javascript">
function difference(oldtime) {
   var nowtime = new Date();
   var milliseconds1 = oldtime.getTime();
   var milliseconds2 = nowtime.getTime();
   var difference = milliseconds2 - milliseconds1;
   var daysDifference = Math.floor(difference/1000/60/60/24);
   difference = difference - daysDifference*1000*60*60*24
   var hoursDifference = Math.floor(difference/1000/60/60);
   difference = difference - hoursDifference*1000*60*60
   var minutesDifference = Math.floor(difference/1000/60);
   difference = difference - minutesDifference*1000*60
   var secondsDifference = Math.floor(difference/1000);
   if (daysDifference < 1 && hoursDifference < 4)
   document.write(' &nbsp;(<span class="lastupdated"><b>' + hoursDifference + ' </b> hours, <b> ' + minutesDifference + ' </b> minutes  ago)');
   else if (daysDifference < 1 && hoursDifference >= 4 && hoursDifference < 20)
   document.write(' &nbsp;(<span class="lastupdated"><b>' + hoursDifference + ' </b> hours ago)');
   else (daysDifference >= 1)
   document.write(' ');
}
</script>


So anything posted under 4 hours ago has
'XX Hours, XX Minutes ago'

Anything posted equal to or over 4 hours ago has
'XX Hours ago'

But my problem is that I want anything posted over 1 day to have nothing after it and I can't seem to get that part working...
AndyP
 
Posts: 165
Joined: Wed Jan 10, 2007 10:10 pm

Postby InSAnE NiNjA » Sat May 28, 2005 11:42 am

umm.. remove..

Code: Select all
   else (daysDifference >= 1)
   document.write(' ');
..nuttier then a squirrel turd..
User avatar
InSAnE NiNjA
 
Posts: 1213
Joined: Sat Jan 25, 2003 6:35 am

Next

Return to Customization

Who is online

Users browsing this forum: No registered users and 1 guest

cron