John Davidson

php - Date mapper doesn't accept the data sent although it seems to be in an acceptable format

0 comments
Message:


My request it like this,


$params = [
'index' => 'reportings',
'type' => 'datax',
'id' => $row["id"],
'body' => [
'id' => $row["id"],
'dateCreated' => "2020-11-20 20:39:53"
'dateUpdated' => "2020-11-20 20:39:53"
]
];
$response = $client->index($params);

and the mapping for these rows are like this,


"dateCreated": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" }, "dateUpdated": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" },

The error is "mapper [dateCreated] cannot be changed from [date] to [text]"


And when I try to send it as epoch, it recognizes it as long. How can I make it recognize it as date data?



My Answer:
't have a specific function called "Date mapper" in PHP. However, you can use the DateTime class in PHP to manipulate and format dates. Here's an example of how you can use the DateTime class to map dates:

php
$date = new DateTime('2022-01-01');
echo $date->format('Y-m-d'); // Output: 2022-01-01

$date->modify('+1 day');
echo $date->format('Y-m-d'); // Output: 2022-01-02

$date->modify('+1 week');
echo $date->format('Y-m-d'); // Output: 2022-01-09


In this example, we create a new DateTime object with the date '2022-01-01' and then use the `modify()` method to add a day and a week to the date. Finally, we use the `format()` method to output the modified dates in the desired format.

Rate this post

5 of 5 based on 4458 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us