TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

May 01, 2024, 03:32:45 AM

Login with username, password and session length
Members
  • Total Members: 3,885
  • Latest: Growner
Stats
  • Total Posts: 195,174
  • Total Topics: 21,220
  • Online today: 124
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 168
  • Total: 168

Change the time format?

Started by IchBin, March 17, 2005, 04:57:31 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

IchBin

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

Not directly..but if you change TPortalBlocks.template.php some you can achieve this... find:

    // 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:

    // 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'])

IchBin

Well that does exactly what I want, but it takes away the option to show that the post was "Today".

Bjørn

Yes....You might put in a if() statement to check if the date is today....hold on.

Bjørn

Ok, like this:

    // 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.

IchBin

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

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.... ::)

IchBin

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

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....(...)