1

I want this output for my JSON, How can I do this timestamp format using PHP?

 **This 1403375851930 is not equal to 2015-09-03 11:40:46**

{"newsfeed":[{"timeStamp": "1403375851930}]}"

this is my Current Output

{"newsfeed":[{"timestamp":"2015-09-03 11:40:46"}]}

my PHP Code

<?php
$query = 'SELECT * FROM newsfeed';
//execute the query using mysql_query
$result = mysql_query($query);
//then using while loop, it will display all the records inside the table
while ($row = mysql_fetch_array($result)) {
$json['newsfeed'][] = $row;
}
?>

Output(the timestamp is in the last)

{"newsfeed":[{"0":"54","id":"54","1":"55e869fe755ea8.63620266","unique_id":"55e869fe755ea8.63620266","2":"News and Events","type":"News and Events","3":"Cosmos","title":"Cosmos","4":"http:\/\/brmhelpdesk.comlu.com\/BRMhelpdesk\/uploads\/cosmos.jpg","image":"http:\/\/brmhelpdesk.comlu.com\/BRMhelpdesk\/uploads\/cosmos.jpg","5":"asd'[sajfpsdgfg\r\nfdfhfgkljghhdsf\r\nasfdjkhjlkjghjhsdfa\r\nasfgfdgjjlkjhgsffsad","description":"asd'[sajfpsdgfg\r\nfdfhfgkljghhdsf\r\nasfdjkhjlkjghjhsdfa\r\nasfgfdgjjlkjhgsffsad","6":"http:\/\/www.brmhelpdesk.comlu.com\/BRMhelpdesk\/uploads\/lugo.png","profilePic":"http:\/\/www.brmhelpdesk.comlu.com\/BRMhelpdesk\/uploads\/lugo.png","7":"2015-09-03 11:40:46","timestamp":"2015-09-03 11:40:46"}]}

1 Answer 1

1

The easiest way to achieve what do you is this :

$timestamp = strtotime('2015-09-03 11:40:46');

In your case :

while ($row = mysql_fetch_array($result)) {
    $row['timestamp'] = strtotime($row['timestamp']);
    $json['newsfeed'][] = $row;
}
Sign up to request clarification or add additional context in comments.

2 Comments

In my Loop I will declare them 1 by 1 then print as an array again?
thanks! it works! but i got another problem is printed as Jan 17, 1970 rofl well anyway you answered what i need thanks again man!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.