Dates getting modified to1970-01-01T00:00:01.659452061Z when writing it to InfluxDb using the InfluxDb php client

I am using PHP Client for InfluxDB - GitHub - influxdata/influxdb-client-php: InfluxDB (v2+) Client Library for PHP

I am inserting points in my measurement along with current timestamp. For the timestamp, I am using as follows -

$time = new \DateTime();
$timezone=new\DateTimeZone('UTC');
$time->setTimestamp($unixTime)->setTimezone($timezone);

And then in then while inserting the point I am using -

->time($time->getTimestamp());

When I echo this variable, I get the correct timestamp, but when I am checkin values in the InfluxDB, all the dates are replaced by

1970-01-01T00:00:01.659452061Z

I even set the timezone to be UTC. I am not sure how to get the current timestamp into InfluxDB. Any help would be appreciated.

Hi @Shubham_khetan,
Have you made sure to set your timestamp precision in the client?

$client = new InfluxDB2\Client([
    "url" => "http://localhost:8086",
    "token" => "my-token",
    "bucket" => "my-bucket",
    "org" => "my-org",
    "precision" => InfluxDB2\Model\WritePrecision::NS
]);

I believe

$time->getTimestamp()

Returns a UNIX timestamp in seconds by default

Hi @Jay_Clifford, I have set the precision to NS in client. When I try to change it to S, I start getting the following error -

Uncaught GuzzleHttp\Exception\ClientException: Client error: resulted in a `422 Unprocessable Entity` response: {"code":"unprocessable entity","message":"failure writing points to database: partial write: field type conflict