Error: non well formed numeric value encountered

Ask about a PHP problem here.
Post Reply
lakc
Posts: 32
Joined: Fri Oct 21, 2011 6:05 pm

Error: non well formed numeric value encountered

Post by lakc »

hey guys,

PHP code
 $posteddate=$row['room_posteddate'];
  $posteddate=date("d-m-Y",$posteddate); <---error points here
  echo "<td>". $posteddate ."</td>";
Error msg : A non well formed numeric value encountered in....

I want to format the date from the query result within the html code, can u pls correct and perhaps refine or simplify it in one statement if its possible within the td tags???
Last edited by jacek on Thu Feb 23, 2012 11:16 pm, edited 2 times in total.
Reason: code tags...
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Correct me please??

Post by jacek »

Does $posteddate contain a number ?
Image
lakc
Posts: 32
Joined: Fri Oct 21, 2011 6:05 pm

Re: Error: non well formed numeric value encountered

Post by lakc »

It contains a date in the format y-m-d

it contains special character hyphen, ... is this the problem?
bowersbros
Posts: 534
Joined: Thu May 05, 2011 8:19 pm

Re: Error: non well formed numeric value encountered

Post by bowersbros »

inside the function try using strtotime() around the second parameter, see if that lets it work?
I don't like to brag, but I wasn't circumcised. I was circumnavigated. ;)

Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Error: non well formed numeric value encountered

Post by jacek »

If it's a MySQL date format you can use the UNIX_TIMESTAMP to turn it into something that will work with date() so in your query you would use
SELECT
    `posts`.`id`,
    `posts`.`title`,
    UNIX_TIMESTAMP(`posts`.`time`) AS `time`
FROM `posts`
Something like that anyway :)
Image
lakc
Posts: 32
Joined: Fri Oct 21, 2011 6:05 pm

Re: Error: non well formed numeric value encountered

Post by lakc »

Jacek's and browserbros's solutions....worked...thanks again guys. thumbs up.
bowersbros
Posts: 534
Joined: Thu May 05, 2011 8:19 pm

Re: Error: non well formed numeric value encountered

Post by bowersbros »

GO with Jacek's solution, it will be faster. :)

Glad we solved it though :D
I don't like to brag, but I wasn't circumcised. I was circumnavigated. ;)

Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Error: non well formed numeric value encountered

Post by jacek »

bowersbros wrote:GO with Jacek's solution, it will be faster. :)
I think using UNIX_TIMESTAMP() in that way does the same thing as strtotime(). But MySQL runs on a separate thread and caches the result for a bit. Both of these are interesting points in an argument about performance but honestly it will make very little difference which you go with ;)
bowersbros wrote:Glad we solved it though :D
Yup :D
Image
Post Reply