Reputation: 3495
I am getting Google Analytics data via API using google-api-php-client
Everything fine except one thing, I can't convert day timestamp into readable value. The day timestamp looks like 20150724, date('M j', $date);
always shows Aug 22 even for different timestamps.
How to fix it?
Upvotes: 0
Views: 719
Reputation: 9227
If you don't tell PHP what the number is, it will assume it's a UNIX timestamp. 20150724 is 22nd August 1970...
So just tell it how it's formatted:
<?php
$google_date = '20150724';
$date = DateTime::createFromFormat('Ymd', $google_date);
echo $date->format('M j');
Upvotes: 2
Reputation: 1585
date() expects the $date to be a timestamp which is the number of seconds since the Unix epoch. Try converting $date with strtotime.
Upvotes: 1