开发者

Can you use the PHP date() with array items?

开发者 https://www.devze.com 2023-02-26 22:45 出处:网络
I have an array $creation_date[] that I am looping throu开发者_JAVA技巧gh. This contains MySQL timestamps. I want to change these timestamps into dates like January 4, 1992. I have this code: date(\'F

I have an array $creation_date[] that I am looping throu开发者_JAVA技巧gh. This contains MySQL timestamps. I want to change these timestamps into dates like January 4, 1992. I have this code: date('F j, Y', $creation_date[$i]) (its in a while loop with $i incrementing it). It is returning an error at that line A non well formed numeric value encountered. Any idea what is wrong?


You first have to use the strtotime() function.

date() assumes a unix timestamp (like time()) as a second argument, and the string coming from mysql is a string :)

Try date('F j, Y', strtotime($creation_date[$i]));


not sure on that error but i think you need strtotime in there: date('F j, Y', strtotime($creation_date[$i]))

if that doesn't work, as you looping if you print the $creation_date[$i] does it print as expected?

0

精彩评论

暂无评论...
验证码 换一张
取 消