MyBB Community Forums

Full Version: $mybb->settings['dateformat'] NOT working properly.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have the Date Formats set up in the configuration as: m-d-Y

I've created a new page to show absent members, however the dateformat is not using the mybb settings format on this page specifically.

Current time now shows relative correct date like: 02-18-2018
This page shows it like: 28-2-2018

What have I done wrong?

$returndate = $users['returndate'];
Still at a loss here.

I've tried searching the MyBB forums for "my_date" (as that is what I'm pretty sure the mybb-->settings part comes from and came up with two threads I believe not related to this at all. One being a bug report from 2016.

Why wouldn't the mybb settings for date format be working?
It's possibly overwritten by your $mybb->user setting for date.

And what's your full code example? What you have is NOT the actual output you're using.
I don't have any settings set up for my accounts date/time besides a timezone selected. My current time on the board shows like "02-21-2018, 11:21 AM" throughout EVERYTHING BUT THIS PAGE.

$query = $db->query("
		SELECT *
		FROM ".TABLE_PREFIX."users
		WHERE ".TABLE_PREFIX."users.usergroup IN (4,6,14,17)
		ORDER BY username ASC
	");
while($users = $db->fetch_array($query))    {
	if($users['away'] == '1')	{
		$users['username'] = format_name($users['username'], $users['usergroup'], $users['displaygroup']);
		$users['awaydate'] = my_date($mybb->settings['dateformat'], $users['awaydate']);
		$returndate = $users['returndate'];
		$awayreason = $users['awayreason'];
		eval("\$absentmember .= \"".$templates->get("absentmember_entry")."\";");
	}
}

I tried changing returndate to follow suit with awaydate like this:
$returndate = my_date($mybb->settings['dateformat'], $users['returndate']);

BUT THEN, if a user did not select a return date it now shows 12-31-1969 instead of Unknown
Why not just do the away=1 in the query as "AND away='1'"?

Can you check your database please to see if indeed the format of the returndate. My returndate is not unix timestamp. So you'll need to convert returndate to unix timestamp then run my_date() function.

This code is from member.php which shows the return date in the profile.
			// PHP native date functions use integers so timestamps for years after 2038 will not work
			// Thus we use adodb_mktime
			if($returnhome[2] >= 2038)
			{
				require_once MYBB_ROOT."inc/functions_time.php";
				$returnmkdate = adodb_mktime(0, 0, 0, $returnhome[1], $returnhome[0], $returnhome[2]);
				$returndate = my_date($mybb->settings['dateformat'], $returnmkdate, "", 1, true);
			}
			else
			{
				$returnmkdate = mktime(0, 0, 0, $returnhome[1], $returnhome[0], $returnhome[2]);
				$returndate = my_date($mybb->settings['dateformat'], $returnmkdate);
			}

			// If our away time has expired already, we should be back, right?
			if($returnmkdate < TIME_NOW)
			{
				$db->update_query('users', array('away' => '0', 'awaydate' => '0', 'returndate' => '', 'awayreason' => ''), 'uid=\''.(int)$memprofile['uid'].'\'');

				// Update our status to "not away"
				$memprofile['away'] = 0;
			}
		}
I believe the return date is stored in like "{$return_day}-{$return_month}-{$return_year}", so you need to explode it and convert it to a timestamp as already explained.

MyBB doesn't store the seconds, minutes, nor hours for this feature.
(2018-02-22, 01:51 AM)Omar G. Wrote: [ -> ]I believe the return date is stored in like "{$return_day}-{$return_month}-{$return_year}", so you need to explode it and convert it to a timestamp as already explained.

MyBB doesn't store the seconds, minutes, nor hours for this feature.

I'm not too worried about seconds, minutes and hours on this part. Just more interested in getting the awaydate to look like the rest of the site formatting for date.

As far as "you need to explode it and convert it to a timestamp" I do not know how to do such and would really appreciate if someone could walk me through step by step. PHP is new to me and I don't understand much of it. Just enough to make a few simple pages necessary other than that I have no clue what I'm doing lol.

THIS HAS BEEN SOLVED BY DOYLECC:
---
If anyone else is having the issue the simple fix is this,
$returndate = my_date($mybb->settings['dateformat'], strtotime($users['returndate']));

However, if the user had an "unknown" return date it says return "Today". I use template conditionals so to fix this I just did
<if $returndate == "Today" then>Unknown<else then><else />{$returndate}</if>
I posted example code in my previous post. You'll want to use mktime() php function.