# Datetime format started\_at and ended\_at PHP problem

**URL:** <https://discuss.dev.twitch.com/t/datetime-format-started-at-and-ended-at-php-problem/18053>\
**Category:** API\
**Created:** [October 4, 2018, 6:31pm UTC](https://discuss.dev.twitch.com/t/datetime-format-started-at-and-ended-at-php-problem/18053 "2018-10-04T18:31:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Smax2k](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/smax2k/32/5231_2.png) [@Smax2k](https://discuss.dev.twitch.com/u/Smax2k)\
**Post date:** [October 4, 2018, 6:31pm UTC](https://discuss.dev.twitch.com/t/datetime-format-started-at-and-ended-at-php-problem/18053/1 "2018-10-04T18:31:23Z")

</div>

Hello, i have a problem with the datetime format, i have this error :  
“Bad Request” status 400  
Message : "parsing time “2018-10-04T18:27:28 00:00” as “2006-01-02T15:04:05Z07:00”: cannot parse “” as “Z07:00"”

My test code for 1 day of clips range :

```
$started_at = date('Y-m-d\TH:i:sP');
$ended_at = date('Y-m-d\TH:i:sP', strtotime($started_at . ' -1 day'));
$game_id = "65632";
GetAPI_clips($game_id,$started_at,$ended_at,$lang);

```

Thank you

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [October 4, 2018, 7:06pm UTC](https://discuss.dev.twitch.com/t/datetime-format-started-at-and-ended-at-php-problem/18053/2 "2018-10-04T19:06:49Z")

</div>

Date needs to be formatted as per `RFC3339`

The error you are getting is a PHP error not a TwitchAPI error, I believe.

You are also setting ended at to before started at. Which is back to front.

Try this instead:

```
$started_at = date(DATE_RFC3339, time() - 86400);
$ended_at = date(DATE_RFC3339);
```

---

<div class="post-metadata">

**Author:** ![Smax2k](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/smax2k/32/5231_2.png) [@Smax2k](https://discuss.dev.twitch.com/u/Smax2k)\
**Post date:** [October 4, 2018, 8:13pm UTC](https://discuss.dev.twitch.com/t/datetime-format-started-at-and-ended-at-php-problem/18053/3 "2018-10-04T20:13:32Z")

</div>

Yes RFC3339 is Y-m-d\TH:i:sP too, i tested your two lines but not working. I have this :  
`{"error":"Bad Request","status":400,"message":"parsing time \"2018-10-03T22:09:37 02:00\" as \"2006-01-02T15:04:05Z07:00\": cannot parse \"\" as \"Z07:00\""}`

I know is not good but is working on this :  
$started\_date = date(‘Y-m-d’, strtotime($started\_at . ’ -1 day’));  
$ended\_date = date(‘Y-m-d’);  
$started\_at = $started\_date.“T00:00:00Z”;  
$ended\_at = $ended\_date.“T00:00:00Z”;

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [October 4, 2018, 8:15pm UTC](https://discuss.dev.twitch.com/t/datetime-format-started-at-and-ended-at-php-problem/18053/4 "2018-10-04T20:15:20Z")

</div>

Please provide all the code and/or the actual request you are making to Twitch API

---

<div class="post-metadata">

**Author:** ![Smax2k](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/smax2k/32/5231_2.png) [@Smax2k](https://discuss.dev.twitch.com/u/Smax2k)\
**Post date:** [October 4, 2018, 8:23pm UTC](https://discuss.dev.twitch.com/t/datetime-format-started-at-and-ended-at-php-problem/18053/5 "2018-10-04T20:23:22Z")

</div>

My request : ‘[https://api.twitch.tv/helix/clips?game\_id=’.$game\_id.’&started\_at=’.$started\_at.’&ended\_at=’.$ended\_at.’&first=100&language=](https://api.twitch.tv/helix/clips?game_id='.%24game_id.'&started_at='.%24started_at.'&ended_at='.%24ended_at.'&first=100&language=)’.$lang;

I think it’s the format of the date that is not good, I try two formats but it still does not work.

Exemple with : echo date(DATE\_RFC3339);  
Output : 2018-10-04T22:21:59+02:00

I think Twitch not like “+02:00” ?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [October 4, 2018, 8:27pm UTC](https://discuss.dev.twitch.com/t/datetime-format-started-at-and-ended-at-php-problem/18053/6 "2018-10-04T20:27:33Z")

</div>

You need to URLencode your parameters

`https://api.twitch.tv/helix/clips?game_id=’.$game_id.’&started_at=’.urlencode($started_at).’&ended_at=’.urlencode($ended_at).’&first=100&language=’.$lang;`

As the `+` is being interpreted as something else and Twitch is not receiving a RFC3339 date from you.

---

<div class="post-metadata">

**Author:** ![Smax2k](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/smax2k/32/5231_2.png) [@Smax2k](https://discuss.dev.twitch.com/u/Smax2k)\
**Post date:** [October 4, 2018, 8:34pm UTC](https://discuss.dev.twitch.com/t/datetime-format-started-at-and-ended-at-php-problem/18053/7 "2018-10-04T20:34:24Z")

</div>

Obviously you are a genius! Thank so much!

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [November 3, 2018, 8:34pm UTC](https://discuss.dev.twitch.com/t/datetime-format-started-at-and-ended-at-php-problem/18053/8 "2018-11-03T20:34:24Z")

</div>

Closed on November 3, 2018, 8:34pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
