# API v3 DateTime Format in PHP: Which Format Should I Provide?

**URL:** <https://community.hubspot.com/t/api-v3-datetime-format-in-php-which-format-should-i-provide/36176>\
**Category:** APIs & Integrations\
**Tags:** php\
**Created:** [April 26, 2021, 7:39pm UTC](https://community.hubspot.com/t/api-v3-datetime-format-in-php-which-format-should-i-provide/36176 "2021-04-26T19:39:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![danhammari](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/danhammari/32/11850_2.png) [@danhammari](https://community.hubspot.com/u/danhammari)\
**Post date:** [April 26, 2021, 7:39pm UTC](https://community.hubspot.com/t/api-v3-datetime-format-in-php-which-format-should-i-provide/36176/1 "2021-04-26T19:39:33Z")

</div>

Is there a particular format I should use when exporting a DateTime value for the PHP API library?

I am creating deals via the API v3 CRM Deals endpoint using the PHP library.

I seem to be unable to set the closedate property for my deals and suspect this may be due to the datetime format that I am providing.

- CLASS: \HubSpot\Client\Crm\Deals\Api\BasicApi.php
- METHOD: create($simple\_public\_object\_input)

The create example in the API Developer Docs provides the following value when setting the closedate:

- “closedate”: "2019-12-07T16:50:06.678Z
- [Accounts Dashboard | HubSpot](https://developers.hubspot.com/docs/api/crm/deals)

This format doesn’t seem to quite align with the DateTimeInterface::ATOM constant in PHP:

- const string [ATOM](https://www.php.net/manual/en/class.datetimeinterface.php#datetime.constants.atom) = “Y-m-d\TH:i:sP”
- example: 2005-08-15T15:52:01+00:00
- [PHP: DateTimeInterface - Manual](https://www.php.net/manual/en/class.datetimeinterface.php#datetime.constants.atom)

Should I instead export the DateTime value as a UNIX\_TIMESTAMP, multiply that value by 1000 to add milliseconds, and provide that number to the PHP library?

Or should I simply supply a raw DateTime object and trust that the PHP Library will take care of the export format for me?

---

<div class="post-metadata">

**Author:** ![danhammari](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/danhammari/32/11850_2.png) [@danhammari](https://community.hubspot.com/u/danhammari)\
**Post date:** [April 26, 2021, 11:02pm UTC](https://community.hubspot.com/t/api-v3-datetime-format-in-php-which-format-should-i-provide/36176/2 "2021-04-26T23:02:57Z")

</div>

It looks like the only option that works is when I convert the DateTime to a UNIX TIMESTAMP, then multiply that number by 1000 to convert it to microseconds.

- $milliseconds = $datetime\_object-\>getTimestamp() \* 1000;

When I supplied a DateTime object I received this error message:

- Invalid input JSON on line 1, column 68: Cannot deserialize instance of `java.lang.String` (truncated…)

When I supplied an RFC3339 (ATOM) DateTime Format I received this error message:

- Property values were not valid: [{\“isValid\”:false,\“message\”:\"2021-04-23T06:00:00+00:00 (truncated…)

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [April 27, 2021, 2:51pm UTC](https://community.hubspot.com/t/api-v3-datetime-format-in-php-which-format-should-i-provide/36176/3 "2021-04-27T14:51:25Z")

</div>

@danhammari

for posterity: here is the doc on [timestamp format](https://developers.hubspot.com/docs/api/faq)
