Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


cut seconds and UTC from time

Posted on 2013-06-26
Medium Priority
Last Modified: 2013-07-01
given manly lines in this format

2007-02-07 05:54:17 UTC
2007-02-07 20:12:06 UTC
2007-02-07 20:50:31 UTC
2007-02-07 20:56:25 UTC
2007-02-07 20:56:32 UTC


2007-02-07 05:54
2007-02-07 20:12
2007-02-07 20:50
2007-02-07 20:56
2007-02-07 20:56
Question by:rgb192
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 15

Expert Comment

by:Jagadishwor Dulal
ID: 39277185
How did you generate the above data? Try this one:
$value="2007-02-07 05:54:17 UTC
2007-02-07 20:12:06 UTC
2007-02-07 20:50:31 UTC
2007-02-07 20:56:25 UTC
2007-02-07 20:56:32 UTC";
$res=explode('UTC', ($value));
for($i=0; $i<sizeof($res)-1; $i++){
			echo date("Y-m-d G:i", strtotime($res[$i]))."<br>";

Open in new window


Author Comment

ID: 39277230
i received input from excel file

your output:
2007-02-07 5:54
2007-02-07 8:12
2007-02-07 8:50
2007-02-07 8:56
2007-02-07 8:56
1969-12-31 7:00
LVL 15

Assisted Solution

by:Jagadishwor Dulal
Jagadishwor Dulal earned 668 total points
ID: 39277235
It was may mistake first see the updated comment now there you must change the time format g to G see below:

for($i=0; $i<sizeof($res)-1; $i++){
			echo date("Y-m-d G:i", strtotime($res[$i]))."<br>";

Open in new window

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 664 total points
ID: 39277271
If these are strings, just do substr() to get the first 16 characters..
echo substr($line, 0, 16);  // abcd

Open in new window

LVL 111

Accepted Solution

Ray Paseur earned 668 total points
ID: 39278679
See http://www.laprbass.com/RAY_temp_rgb192.php

This is all covered in the article here:

Take careful note of the date_default_timezone.  You need to understand this with absolute certainty!

<?php // RAY_temp_rgb192.php


$arr = array
( '2007-02-07 05:54:17 UTC'
, '2007-02-07 20:12:06 UTC'
, '2007-02-07 20:50:31 UTC'
, '2007-02-07 20:56:25 UTC'
, '2007-02-07 20:56:32 UTC'

$pat = 'Y-m-d H:i';

foreach ($arr as $inp)
    $out = date($pat, strtotime($inp));
    echo "<br/>$inp ==> $out";

Open in new window

Best, ~Ray

Author Closing Comment

ID: 39291146
I prefer the date outputs rather than substr because I want to modify date output (but I did not ask this).  All answers are good thanks

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses four methods for overlaying images in a container on a web page
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question