Converting retrieved datetime from database

user7208682

I'm trying to send the date to my Android device in JSON format. Also, the time is in 24 hours format. How can I change this into 12 hours format?

PHP

<?php
$sql = "SELECT * from news Order by n_date Desc";
$con = mysqli_connect($server_name, $mysql_user, $mysql_pass, $db_name);

$result = mysqli_query($con, $sql);
$response = array();
while ($row = mysqli_fetch_array($result)) {
    array_push($response, array("title" => $row[2], "content" => $row[3], "n_date" => $row[4]));
}

echo json_encode(array("news_response" => $response));

mysqli_close($con);
?>

The JSON response:

{"news_response":[{"title":"news","content":"content","n_date":"2016-11-12 10:47:23"}]}

I am trying to convert the 2016-11-12 to something like November 12, 2016 10:47:23. How do I do this?

I couldn't find any example online.

2oppin

in PHP:

echo (new DateTime('2016-11-12 10:47:23'))->format('F d, y GA:i:s');

in MySQL:

SELECT concat(MONTHNAME(date),' ', DAY(date), ' ', TIME(date)) from news;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Subtraction using DateTime retrieved from database giving strange results

Data not retrieved from database

Object Retrieved From Database in Laravel

setting variables against data retrieved from a database

Entity retrieved from database with same case as in query

How to access property of an object that was retrieved from database?

how to shuffle the data retrieved from the database

To create a dictionary of data retrieved from the database

Display values retrieved from database in a table

Autoplay videos which location retrieved from database

Java hide null values retrieved from a database

How to print retrieved data from a database

How to format the data retrieved from a database

To display the records retrieved from database into a dialog box

how to avoid repeated values retrieved from database?

How to make an image retrieved from a database responsive?

HTML retrieved from database does not appear correct

Text after hyphen ( - ) is not retrieved from Database

Ruby on Rails retrieve datetime by converting it from UTC to user's time zone from database by querying date

R Converting from datetime to date

Converting from DateTime to string in Julia

Python converting from string to datetime

display data retrieved from database from servlet to jsp file

Remove unwanted spaces from values retrieved from sql database

How to cast the value from the retrieved value from Database in laravel?

Select with datetime from database

Converting datetime not converting datetime

PHPExcel converting from a database to xlsx

Converting garbled characters from database