Jump to the post that solved this thread.
Solved: 1 Year, 7 Months, 4 Weeks ago non-numeric warning with my_date function
#1
Solved: 1 Year, 7 Months, 4 Weeks ago
Hello guys, I'm trying to convert some timestamps into readable dates using the my_date function.
When I run the function without custom time format it works well.
When I use the custom format I wish, it returns me a warning concerning the Year piece (I assume the problem comes with Year due to function outputs, pasted at the end of this post).

Custom format I'm trying to use:
F j Y - H:i

Function setup I'm using:
my_date("F j Y - H:i", $mybb->settings['dateformat'], $serial['date'])

Warning I'm being returned when the custom format is added into the function:
<error>
	<dateline>1607729566</dateline>
	<script>inc/functions.php</script>
	<line>539</line>
	<type>2</type>
	<friendly_type>Warning</friendly_type>
	<message>A non-numeric value encountered</message>
	<back_trace>#0  errorHandler->error() called at [/inc/functions.php:539]
#1  my_date() called at [/custom.php:112]
</back_trace>
</error>

Here are the outputs I get:

Without custom format
12-01-2020

With custom format:
December 1 185274 - 11:00

Original timestamp:
1606817915

Do you have any clue about what's wrong with my setup?
Reply
#2
Solved: 1 Year, 7 Months, 4 Weeks ago
Why do you send 2 formats to my_date ?
What you're doing is to trying to transform the default format into a date and add it an offset which is the timestampt to treat...

/**
 * Turn a unix timestamp in to a "friendly" date/time format for the user.
 *
 * @param string $format A date format (either relative, normal or PHP's date() structure).
 * @param int $stamp The unix timestamp the date should be generated for.
 * @param int|string $offset The offset in hours that should be applied to times. (timezones) Or an empty string to determine that automatically
 * @param int $ty Whether or not to use today/yesterday formatting.
 * @param boolean $adodb Whether or not to use the adodb time class for < 1970 or > 2038 times
 * @return string The formatted timestamp.
 */
function my_date($format, $stamp=0, $offset="", $ty=1, $adodb=false)

Just do my_date("F j Y - H:i", $serial['date'])
Do not ask me help through PM or Discord
Reply
#3
Solved: 1 Year, 7 Months, 4 Weeks ago
(2020-12-12, 08:56 AM)Crazycat Wrote: Why do you send 2 formats to my_date ?
What you're doing is to trying to transform the default format into a date and add it an offset which is the timestampt to treat...

/**
 * Turn a unix timestamp in to a "friendly" date/time format for the user.
 *
 * @param string $format A date format (either relative, normal or PHP's date() structure).
 * @param int $stamp The unix timestamp the date should be generated for.
 * @param int|string $offset The offset in hours that should be applied to times. (timezones) Or an empty string to determine that automatically
 * @param int $ty Whether or not to use today/yesterday formatting.
 * @param boolean $adodb Whether or not to use the adodb time class for < 1970 or > 2038 times
 * @return string The formatted timestamp.
 */
function my_date($format, $stamp=0, $offset="", $ty=1, $adodb=false)

Just do my_date("F j Y - H:i", $serial['date'])

Oh silly me. I was convinced that "$mybb->settings['dateformat']" was a default part of the function. I copy/pasted it from a search without checking how it works.
Reply
Jump to the post that solved this thread.


Forum Jump:


Users browsing this thread: 1 Guest(s)