vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Newbie Question: How to Change Format of vb date? (https://vborg.vbsupport.ru/showthread.php?t=224022)

BENBOBBY 09-26-2009 06:35 PM

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:

Lynne 09-26-2009 07:04 PM

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


BENBOBBY 09-26-2009 07:40 PM

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.

Lynne 09-26-2009 09:48 PM

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.

BENBOBBY 09-27-2009 09:11 AM

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.

Lynne 09-27-2009 03:09 PM

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.

BENBOBBY 09-27-2009 09:07 PM

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?

Lynne 09-27-2009 09:34 PM

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.

BENBOBBY 09-28-2009 09:08 AM

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.

Lynne 09-28-2009 02:03 PM

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.

BENBOBBY 09-29-2009 09:27 AM

I cannot find any hooks in the style templates under memberslist!

However, I created a new plugin and guessed that "memberlist_complete" would be the correct location.

How would I go about changing the date format of the Last Visit then? I tried the following;

Quote:

$this->post['lastvisit_date'] = vbdate($this->registry->options['dateformat'], $this->post['lastvisit_date'], false);
How do you know what to put inside the ['....']? At the moment Im just kind of guessing at the names, is there a dictionary of vbulletin terms available anywhere?

Lynne 09-29-2009 02:36 PM

Look at the member.php page. That is where I am saying to look for the hooks, not in the templates.

At the top is the member_start hook. Simply set the *option* to what you want. ie.
PHP Code:

$vbulletin->options['dateformat'] = 'whatever'


(Or whatever option you want to change.)

BENBOBBY 09-29-2009 04:55 PM

Thanks for the reply.

memberlist_bit seemed to be the hook that in fact effects the date format.

Sorry if this is a silly question, but what should I put for the $timestamp part?

Quote:

$vbulletin->options['dateformat'] = ('d/m', ??????, false);

Lynne 09-29-2009 05:55 PM

What I'm saying is.... just change the option. If you look at the vboptions page, and find where dateformat is defined, you'll see the options in the page source. For instance, if you wanted to change the Yesterday/Today option, find the option in the vBulletin Options page and look at the page source:
Code:

<tbody><tr valign="top">
        <td class="optiontitle" title="$vbulletin->options['yestoday']" colspan="2"><div class="smallfont" style="float:right"> <a href="options.php?do=editsetting&amp;varname=yestoday">[Edit]</a>  <a href="options.php?do=removesetting&amp;varname=yestoday">[Delete]</a> </div><div>Datestamp Display Option<a name="yestoday"></a></div></td>
</tr>
</tbody><tbody id="tbody_yestoday">
<tr valign="top">
        <td class="alt1"><div class="smallfont"title="$vbulletin->options['yestoday']">This option controls the display of dates throughout your forum<br /><br />'Normal' uses the date and time formats below this option.<br />
<br />

'Yesterday / Today' will show 'Yesterday' and 'Today' for dates that fall in those periods.<br />
<br />
'Detailed' will show times such as '1 Minute Ago', '1 Hour Ago', '1 Day Ago', and '1 Week Ago'.</div></td>
        <td class="alt1"><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr valign="top"><td><div class="smallfont">
<div class="ctrl_">                <label for="rb_setting[yestoday]0_73"><input type="radio" name="setting[yestoday]" id="rb_setting[yestoday]0_73" tabindex="1" value="0" title="name=&quot;setting[yestoday]&quot; value=&quot;0&quot;" />Normal</label><br />
                <label for="rb_setting[yestoday]1_73"><input type="radio" name="setting[yestoday]" id="rb_setting[yestoday]1_73" tabindex="1" value="1" title="name=&quot;setting[yestoday]&quot; value=&quot;1&quot;" checked="checked" />Yesterday / Today</label><br />
                <label for="rb_setting[yestoday]2_73"><input type="radio" name="setting[yestoday]" id="rb_setting[yestoday]2_73" tabindex="1" value="2" title="name=&quot;setting[yestoday]&quot; value=&quot;2&quot;" />Detailed</label><br />
</div>        </div></td><td align="right" style="padding-left:4px"><a class="helplink" href="#" onclick="js_open_help('options', 'options', 'yestoday'); return false;"><img src="../cpstyles/vbtech/cp_help.gif" alt="" border="0" title="Click for help on this option" /></a> </td></tr></table></td>

</tr>
</tbody>

I highlighted the allowed values - 0, 1, or 2. If you wanted the date to use Yesterday/Today on that page, that would mean you want the value set to 1. So, you would put this in the plugin:
PHP Code:

$vbulletin->options['yestoday'] = '1'


BENBOBBY 09-29-2009 08:42 PM

All done. Many thanks for your help and patience :)


All times are GMT. The time now is 04:36 AM.

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.02261 seconds
  • Memory Usage 1,789KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (4)bbcode_php_printable
  • (7)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (15)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete