Change date format in array and return a json

format json date to mm/dd/yyyy
how to pass date in json format
json date converter
rest api json date format
how to pass date in json format in postman
json date format java
convert json "/date(1297246301973)/" to javascript date only
json date object

How to change date format in my array

print_r($data);

[01] => Array
    (
        [status] => Pending
        [number] => 123
        [DESCRIPTION] => description
        [STARTDATE] => 1544079879
        [RESTOREDATETIME] => 1544080492
    )

I want to change date format

$data = $my->getCustFunction();
header("Content-Type: application/json");
print json_encode($data);
return;

i wan to return like this

[01] => Array
    (
        [status] => Pending
        [number] => 123
        [DESCRIPTION] => description
        [STARTDATE] => 1544079879(d/m/y)
        [RESTOREDATETIME] => 1544080492
    )

Assuming you have multiple subarrays:

foreach($data as $key => $value)
{
   $data[$key]['STARTDATE'] = date('d/m/y',$value['STARTDATE']);
}

Change date format in array and return a json, Change date format in array and return a json. format json date to mm/dd/yyyy json date format json date converter convert json "/date(1297246301973)/" to  Answer 2. You can use this to get a date from JSON: var date = eval(jsonDate.replace(/\/Date\ ( (\d+)\)\//gi, "new Date ($1)")); And then you can use a JavaScript Date Format script (1.2 KB when minified and gzipped) to display it as you want. Answer 3.

try this

when you get data and before return data, use this code

date('d/m/y', 1544079879);

to your STARTDATE field

Loop below

foreach($data as $key => $value)
{
   $data[$key]['STARTDATE'] = date('d/m/y',$value['STARTDATE']);
}

JavaScript JSON Date Parsing and real Dates, The JSON.stringify() method converts a JavaScript object or value to including only the specified properties if a replacer array is specified. value: The value to convert to a JSON string. replacer Optional: A The instances of Date implement the toJSON() function by returning a string (the same as date. I created a very simple api in order to reproduce the issue and this is how I fixed the date format : // GET api/values [HttpGet] public JsonResult Get() {var date = DateTime.Today.Date.ToString("yyyy-MM-dd"); return Json(date);} Best regards, Maher

Here it is:

$data['01']['STARTDATE'] = date("d/m/y", $data['01']['STARTDATE']);

[UPDATE] Your array:

$data = [
    '01' => [
        'status' => 'Pending',
        'number' => 123,
        'DESCRIPTION' => 'description',
        'STARTDATE' => 1544079879,
        'RESTOREDATETIME' => 1544080492,
    ]
];

print_r($d);

Loop though array items and convert STARTDATE to 'd/m/y' format

With 'pass by reference':

foreach ($data as &$item) {
    $item['STARTDATE'] =  date("d/m/y", $item['STARTDATE']);
}

Pay attention to '&' in foreach statement, without it you could't change $item inside the loop (http://php.net/manual/en/language.references.pass.php)

With 'classic' style:

foreach ($data as $key => $value) {
    $data[$key]['STARTDATE'] =  date("d/m/y", $value['STARTDATE']);
}

Date formatting parameters: According to http://php.net/manual/ru/function.date.php d - Day of the month, 2 digits with leading zeros m - Numeric representation of a month, with leading zeros y - A two digit representation of a year / - separator

JSON.stringify(), Firstly, regardless of whether you actually want to transform the fields into dates,​you will need to format them for display. This formatting should be applied in the  JSON has become a rather prevalent serialization format in recent years. For Web based applications one could say it’s become the serialization format. It’s used for transport serialization for just about anything REST related these days, for configuration management, for storage and data representation in many database formats (NoSql).

Convert all dates in an array to date format, JS JSON. JSON Intro JSON Syntax JSON vs XML JSON Data Types JSON Parse JSON There are generally 3 types of JavaScript date input formats: If you want to modify the time relative to UTC, remove the Z and add +HH:MM or Date​.parse() returns the number of milliseconds between the date and January 1, 1970:  Arrays in JSON are almost the same as arrays in JavaScript. In JSON, array values must be of type string, number, object, array, boolean or null. In JavaScript, array values can be all of the above, plus any other valid JavaScript expression, including functions, dates, and undefined.

JavaScript Date Formats, jsonText (Text): The text to convert from a JSON string to an Appian value. Returns. One of: Dictionary, List of Integer, List of Decimal, List of Text, List of Date and Time (when supported datetime format is found) Array, List of Variant. The ConvertTo-Json cmdlet converts any .NET object to a string in JavaScript Object Notation (JSON) format. The properties are converted to field names, the field values are converted to property values, and the methods are removed. You can then use the ConvertFrom-Json cmdlet to convert a JSON-formatted string to a JSON object, which is easily managed in PowerShell. Many web sites use JSON

a!fromJson() Function - Appian 19.4, The other parse* methods are similar in that they return a JSON String but for different parameter Date based on the yyyy-MM-dd'T'HH:mm:ssZ date format  These functions, json_encode() and json_decode(), make it easy to work with JSON and create JSON web services from PHP. A simple way to get your feet wet with web services is to return a date in JSON format. Here’s how you can do that: Open your text editor or programming IDE and create a new empty file. Place the following code within the file:

Comments
  • you want to return in d\m\y format or do you want to concat (d\m\y) at the end of the string.
  • i wan to convert format
  • Can you tell us, just for clarity, what format the date in currently in please.
  • it return like this 1544079879. i don't know this
  • I would be tempted to do this in the getCustFunction() rather than as an after thought
  • Um... d/m/y is what the OP wanted
  • Try this: $value['STARTDATE'] = $value['STARTDATE']."(d\m\y)";
  • But this one will generate 01/01/70 which is obviously wrong
  • i print data after this but still not convertying itshow this 1544079879
  • How would this affect your original array if you didn't pass by reference or use $data[$key]['STARTDATE'] = ...
  • I didn't downvote, but helpful tip: Explain your changes and do not include <?php ?>
  • Do not use pass by reference if you don't have to. It could be very dangerous for unexperienced PHP developers. Instead use $data[$key]['STARTDATE'] = ...