MyBB Community Forums

Full Version: Return Date on Custom Page
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am attempting to add a return date to a custom page. However I've gone through several mishaps.

At first I had this which works IF the user had a return date set, otherwise instead of saying Unknown it would say Today (which is false).
		$returndate = my_date($mybb->settings['dateformat'], strtotime($users['returndate']));

So I replaced it with this but then EVERYTHING said Unknown, even if there was a return date set.
		$returndate = my_date($mybb->settings['dateformat'], strtotime($users['returndate']));
		if(!$returndate)  {
				$returndate = "Unknown";
		}

I ended up taking everything out to use MyBBs core coding found in member.php regarding returndates. However once again I am back to EVERYTHING saying Unknown.
		if($memprofile['returndate'] == '')
		{
			$returndate = "$lang->unknown";
		}
		else
		{
			$returnhome = explode("-", $memprofile['returndate']);

			// 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);
			}
		}

I have also attempted to change $returnhome = explode("-", $memprofile['returndate']); to the following with no change to the Unknown display issue even if a date is added.
$returnhome = explode("-", $returndate);
The my_date function doesn't print "Unknown". To use the member.php code you must change $memprofile with $users.
(2018-10-28, 08:10 PM)chack1172 Wrote: [ -> ]The my_date function doesn't print "Unknown". To use the member.php code you must change $memprofile with $users.

Changed instances of $memprofile with $users as seen below HOWEVER now the return date is displaying 30-11-1999 for everyone which while being an incorrect date is also in the incorrect format that the settings uses.
        if($users['returndate'] == '')
		{
			$returndate = "$lang->unknown";
		}
		else
		{
			$returnhome = explode($users['returndate']);

			// 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);
			}
		}
Are you sure that the variable is users and not user?
If I use users I receive an internal MyBB warning and it displays a date but a very incorrect date with the warning at the top of the page.

If I use user for example test account return should be 12-14-2020 but instead it is displaying Unknown

SOLVED

Ended up clicking in my brain to try this which has resulted in success.

        if($users['returndate'] == '') {
            $users['returndate'] = "$lang->unknown";
        }
        else {
            $users['returndate'] = my_date($mybb->settings['dateformat'], strtotime($users['returndate']));
        }