Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

February 04, 2023, 10:13:24 PM

Login with username, password and session length
Members
  • Total Members: 3856
  • Latest: Bixby
Stats
  • Total Posts: 193960
  • Total Topics: 21131
  • Online today: 56
  • Online ever: 3540
  • (September 02, 2022, 06:38:54 PM)
Users Online
Users: 0
Guests: 32
Total: 32

Author Topic: Change the time format?  (Read 6025 times)

0 Members and 1 Guest are viewing this topic.

Offline IchBin

  • Friends
  • *
  • Posts: 16231
Change the time format?
« on: March 17, 2005, 09:57:31 AM »
I was wondering if it would be possible to change the way the time format is displayed in places like the Recent topics and shoutbox. I don't want it displayed like this  March 16, 2005, 20:39. I'd like to change it to something like 3/16/05 8:39 pm if possible. I know you can change it in the forum settings but this doesn't seem to over ride profile preference. Can this be controled through TP and over ride user preference?

Bjørn

  • Guest
Re: Change the time format?
« Reply #1 on: March 17, 2005, 10:45:55 AM »
Not directly..but if you change TPortalBlocks.template.php some you can achieve this... find:

Code: [Select]
    // Output the topics
    foreach($what as $w){
            echo '<span class="smalltext"><a href="'.$w['href'].'"> '.$w['time'];
            if(!$w['new'])


The key here is the $w['time']. That contain the already converted date string. But it also exist a $w['timestamp'] , which can be put in the date function, which take parameters just like setting the string in admin section. Like:

Code: [Select]
    // Output the topics
    foreach($what as $w){
            echo '<span class="smalltext"><a href="'.$w['href'].'"> '.date("n/j/y h:i a",$w['timestamp']);
            if(!$w['new'])

Offline IchBin

  • Friends
  • *
  • Posts: 16231
Re: Change the time format?
« Reply #2 on: March 17, 2005, 05:42:33 PM »
Well that does exactly what I want, but it takes away the option to show that the post was "Today".

Bjørn

  • Guest
Re: Change the time format?
« Reply #3 on: March 18, 2005, 03:04:51 AM »
Yes....You might put in a if() statement to check if the date is today....hold on.

Bjørn

  • Guest
Re: Change the time format?
« Reply #4 on: March 18, 2005, 03:34:17 AM »
Ok, like this:

Code: [Select]
    // Output the topics
    foreach($what as $w){
            echo '<span class="smalltext"><a href="'.$w['href'].'">';
            if(date("z",$w['timestamp'])==date("z",time()) && date("Y",$w['timestamp'])==date("Y",time())){
               echo '<b>Today </b>at '.date("h:i a",$w['timestamp']);
            }
            else{
              echo date("n/j/y h:i a",$w['timestamp']);
            }
            if(!$w['new'])

What happens here is that the if() statement check 2 things - if the daynumber of the year the message was written is the same as the current day. At the same time  it checks if it is the same year as the year we are in. In case you got a message that was last year - but still on day 73 for example.

Then it just outputs a string along with the date , formatted to just hours, and minutes. If not true, it outputs the whole date as usual.

I haven't tested it though.

Offline IchBin

  • Friends
  • *
  • Posts: 16231
Re: Change the time format?
« Reply #5 on: March 18, 2005, 05:17:50 PM »
works like a charm Bloc. Thanks! I seen in a post that you don't think you know php very well. Well I tend to disagree.. lol  Do you know other program languages? How did you learn php?

Bjørn

  • Guest
Re: Change the time format?
« Reply #6 on: March 19, 2005, 03:48:14 AM »
Well, I only started on it about two years ago. :) Reason: my wife needed help to start a forum..at the time I used YabbSE with supermod installed, and as probably some of you know, it was not always stable, at least some versions.

But graphics is really my field, just had always a knack for programming. I tinkered some years with the Amiga, and learnt a lot there. So when it was needed to learn PHP I bought a book : PHP for absolute beginners ;D , and went from there. Btw, the net is an incredible palce to search for info and programming problems...

So I guess it just stuck what I found/read. One day my wife - who really runs that forum, wanted a gallery integrated, not another script, and a quiz function like the poll. And so I began....after alot of trial I eventually got a working script and its been enhanced a bit, but still the same base.

The gallery is just a simple "show pictures/upload/category" thing with no commenting, but the quiz I am somewhat proud of. :) It works like this:

- a member start a new topic+quiz, (like topic+poll) and insert questions + correct answers. Also how many max points an answer can have and links to pictures if she/he want to show a illustrative picture next to the question.
- members answer each one by writing in a textfield(plenty of room for extra short comments to the creator/admin , which they often do.)
- when done, it gets sent in awaiting someone to set points to them.
- That someone is either an admin or the creator. We basically trust our members, so they usually correct it on their own. When each contribution is done it gets a total, when the quiz is closed, results show up over which members scored most. Some of them is regualr, and the winner get titles like "member of the month" , that sort of thing.

But themes is what got me really working, since it is a challenge to delve through the existing theme code and change it to look like you want - without rendering the theme useless.... ::)

Offline IchBin

  • Friends
  • *
  • Posts: 16231
Re: Change the time format?
« Reply #7 on: March 19, 2005, 05:29:29 PM »
Awesome...you give me hope! I've always wanted to learn programming in one way or another. I've learned quite a bit just from messing with your themes and stuff. :) I've been thinking about picking up some books so maybe I'll take a look at that one. I have to build a website for a non-profit company pretty soon, so maybe I'll see if I can't work some php into it. :)

Bjørn

  • Guest
Re: Change the time format?
« Reply #8 on: March 20, 2005, 02:18:46 AM »
I think the key is: start easy..meaning don't rebuild the wheel, but at the same time get the simplest of wheels, so you are sure to follow the logic behind the wheel! :)

In a conversation a while back, I was talking "code" to a guy obvouisly knowing a lot more than me..and he used terms that I haven't even heard of. I mean, if he explained what they did, I understood...but thats what the simple wheel analogy refer too: get solutions, but preferably solutions you understand...

Do try the book, I think maybe its out there on the net too in shape of a pdf....(...)