How can i convert a datetime in the format yyyy-mm-dd H:i:s
to yyyy-mm-ddT00:00:00Z (UTC)
. As my default timezone is not in UTC but i can set that for this conversion. for Amazon CloudSearch supporting format.
Asked
Active
Viewed 1,595 times
-1

Narendrasingh Sisodia
- 21,247
- 6
- 47
- 54

Sanjay
- 761
- 14
- 25
-
And what you have tried. I think you've got multiple duplicate questions related to it – Narendrasingh Sisodia Aug 04 '15 at 09:34
-
http://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php/2167925#2167925 – Mark Baker Aug 04 '15 at 09:35
-
I want to convert the date available in mysql database to Amazon CloudSearch supporting format. – Sanjay Aug 04 '15 at 09:35
-
Mark it is not giving the format Amazon accept. Uchiha Can you get me one link? – Sanjay Aug 04 '15 at 09:39
-
What's so difficult about `$myDateTime = DateTime::createFromFormat('Y-m-d H:i:s', $dateString); $newDateString = $myDateTime->format('Y-m-d\T00:00:00\Z (\U\T\C)');` – Mark Baker Aug 04 '15 at 09:49
2 Answers
2
Simply try using gmdate
function as
$timestamp = gmdate('Y-m-d\TH:i:s\Z P');
echo $timestamp;

Narendrasingh Sisodia
- 21,247
- 6
- 47
- 54
1
Try this
$old_format = "2015-06-07 11:05:10";
$new_format = date("Y-m-d\TH:i:s\Z", strtotime($old_format));
echo $new_format;

Kamlesh Suthar
- 182
- 2
- 8