Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 09-26-2009, 07:35 PM
BENBOBBY BENBOBBY is offline
 
Join Date: Sep 2009
Posts: 37
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Newbie Question: How to Change Format of vb date?

Hi,

Ive downloaded and installed an add-on called "Last Seen Online" (https://vborg.vbsupport.ru/showthread.php?t=123366) which shows when users were last online in their postbit. It works as intended, and displays the following:

Last Online: 26/09/2009 21.35PM

I believe the relevent code is:

Quote:
$this->post['lastseen_date'] = vbdate($this->registry->options['dateformat'], $this->post['lastactivity'], true);


Unfortuately however, this is wider than the postbit on my forum and goes on to a second line which looks messy. So I was hoping to make it shorter. For example:

Last Online: 26/09 21.35PM


Or ideally in a more user friendly format;

Last Online: Today 21.35PM


My programming skills are a bit lacking but I had a go and tried making the following adjustment:

Quote:
$this->post['lastseen_date'] = vbdate[d/m], $this->post['lastactivity'], true);

Not surprisingly this gave an error! So what is the correct markup to change the date format (btw I realise you can change the overall Date/Time options from the AdminCP, but I only wanted to change this)?

Many Thanks. :up:
Reply With Quote
  #2  
Old 09-26-2009, 08:04 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

From the API:
Quote:
vbdate (line 3462) Formats a UNIX timestamp into a human-readable string according to vBulletin prefs
Note: Ifvbdate() is called with a date format other than than one in $vbulletin->options[], set $locale to false unless you dynamically set the date() and strftime() formats in the vbdate() call.
  • return: Formatted date string
string vbdate (string $format, [integer $timestamp = TIMENOW], [boolean $doyestoday = false], [boolean $locale = true], [boolean $adjust = true], [boolean $gmdate = false], [array $userinfo = ''])
  • string $format: Date format string (same syntax as PHP's date() function)
  • integer $timestamp: Unix time stamp
  • boolean $doyestoday: If true, attempt to show strings like "Yesterday, 12pm" instead of full date string
  • boolean $locale: If true, and user has a language locale, use strftime() to generate language specific dates
  • boolean $adjust: If true, don't adjust time to user's adjusted time .. (think gmdate instead of date!)
  • boolean $gmdate: If true, uses gmstrftime() and gmdate() instead of strftime() and date()
  • array $userinfo: If set, use specified info instead of $vbulletin->userinfo
Reply With Quote
  #3  
Old 09-26-2009, 08:40 PM
BENBOBBY BENBOBBY is offline
 
Join Date: Sep 2009
Posts: 37
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi Lynne,

Thanks for the quick reply. Unfortunately to someone without much programming experience that is pretty difficult to follow! I tried various permutations of the following:

Quote:
$this->post['lastseen_date'] = vbdate($format, [$doyestoday = true], $this->post['lastactivity'], true);

But sadly still get an error. Am I on the right lines?
Thanks.
Reply With Quote
  #4  
Old 09-26-2009, 10:48 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Basically, there are several variables that may be passed to that function. They are listed in the order they need to be passed. The values written in parenthesis are the default values if you don't pass anything. So, for instance, if you don't pass anything in the third slot (where it says " [boolean $doyestoday = false]"), then $doyestoday will be false. Since you want it to be true, you would pass the word "true" (no quotes) in the third slot (as in your exampe above):
PHP Code:
vbdate($this->registry->options['dateformat'], $this->post['lastactivity'], true); 
$this->registry->options['dateformat'] means to use the dataformat that you set in your options. If you need that to be changed, as the API says, you would use the same syntax as PHP's date() function.
Reply With Quote
  #5  
Old 09-27-2009, 10:11 AM
BENBOBBY BENBOBBY is offline
 
Join Date: Sep 2009
Posts: 37
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for the reply. It now shows the following;

Last Online: 26/09 21.35PM

Quote:
$this->post['lastseen_date'] = vbdate('d/m', $this->post['lastactivity'], true);

However, even though I believe I have the slot for $doyestoday set as true, its still not showing it in the format of;

Last Online: Yesterday 21.35PM

As I really wanted. What am I missing?
Thanks.
Reply With Quote
  #6  
Old 09-27-2009, 04:09 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What date format are you getting instead? Is it changing at all? Try putting d/m to something else and see if it works - it could be that the code can't translate that to today/yesterday.
Reply With Quote
  #7  
Old 09-27-2009, 10:07 PM
BENBOBBY BENBOBBY is offline
 
Join Date: Sep 2009
Posts: 37
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi Lynne,

Yeah it has changed. It was "Last Online: 26/09/2009 21.35PM" now its shorter without the year and fits in the postbit "Last Online: 26/09 21.35PM" which is good.

Ideally I would have liked it in the format of Today/Yesterday as Ive seen on other forums, but maybe they had it set like that in the overall date/time options. Any ideas?
Reply With Quote
  #8  
Old 09-27-2009, 10:34 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you look at the code, this is the line that must eval to true in order for it to apply today/yesterday:

PHP Code:
    if ($format == $vbulletin->options['dateformat'] AND $doyestoday AND $vbulletin->options['yestoday']) 
So, if any of those eval to false, then it will not apply today/yesterday to the date.
Reply With Quote
  #9  
Old 09-28-2009, 10:08 AM
BENBOBBY BENBOBBY is offline
 
Join Date: Sep 2009
Posts: 37
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok I had to enable "Yesterday / Today" settings globally. The reason I didnt want to do this initially as obviously it changes the format of other dates on the forum.

So now, how can I change "Last Visit" column Members List back to the date format of d/m/y? Ive searched for "dateformat" in all the templates listed under Members List, but cant find anything. Where can I set this setting?

Thanks.
Reply With Quote
  #10  
Old 09-28-2009, 03:03 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Create a plugin using a hook location on that page that sets that option to what you want. Look at the top of the php page and see if a hook is at the start and use that one.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:38 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05152 seconds
  • Memory Usage 2,256KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_php
  • (5)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete