MyBB Hacks

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?

PHP Code:
$returndate = $users['returndate'];

returndate is stored as a string in users table.

PHP Code:
$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'm really not sure what that means? Where do I go to fix this issue? :/

Which one doesn't work as intended? The returndate as stated in the first post or the awaydate?

(02-22-2018 03:49 AM)Niki Wrote: [ -> ]I'm really not sure what that means? Where do I go to fix this issue? :/
returndate is saved as a plain text in users table. It is "formatted" as j-n-Y. You can't use $mybb->settings['dateformat'] directly into it. You need to convert it to UNIX Timestamp first.
Returndate did not work as it should, awaydate is just fine.

Where do I go to convert this to UNIX Timestamp?
There are several ways to do that, either using mktime (you need to explode the returndate first to get month, day and year), strtotime (since it is already in day-month-year and using dash (-) as a separator, you can use it directly) or by using DateTime::createFromFormat / date_create_from_format (need at least PHP 5.3, you can also use it directly).
Reference URL's