K Ф February 2016

Correct date format for publication date youtube api

Getting the following error when I try to put the date in the follwing format:

date_format(date_create($this->output->publication_date), 'Y-m-d H:i:s');

"Invalid value for: Invalid format: \"2015-04-14 00:00:00\" is malformed at \" 00:00:00\"

"Invalid value for: Invalid format: \"2015-04-14 00:00:00\" is malformed at \" 00:00:00\"

What is the correct format that is needed to set the publication date when uploading a video to youtube?

According to the youtube api the format should be

YYYY-MM-DDThh:mm:ss.sZ

How to do this correctly in PHP?

Answers


Matteo February 2016

You need to use the ISO 8601 format, see here for the correct selector.

As example, you can use it in your code as follow:

$date = date_create($this->output->publication_date);
$formatted = $date->format('c'); 

or

date_format(date_create($this->output->publication_date), 'Y-m-d\TH:i:s.Z\Z');

hope this help

Post Status

Asked in February 2016
Viewed 1,035 times
Voted 6
Answered 1 times

Search




Leave an answer