?
Solved

cut seconds and UTC from time

Posted on 2013-06-26
6
Medium Priority
?
250 Views
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



want

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
0
Comment
Question by:rgb192
6 Comments
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
ID: 39277185
How did you generate the above data? Try this one:
<?php
$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

0
 

Author Comment

by:rgb192
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
0
 
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

0
Technology Partners: 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!

 
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

0
 
LVL 111

Accepted Solution

by:
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:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

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

<?php // RAY_temp_rgb192.php
error_reporting(E_ALL);


// THIS MATTERS - A LOT!
date_default_timezone_set('UTC');


// TEST DATA
$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'
)
;

// FORMATTING PATTERN
$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
0
 

Author Closing Comment

by:rgb192
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
0

Featured Post

Technology Partners: 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

This article discusses how to implement server side field validation and display customized error messages to the client.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to count occurrences of each item in an array.
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
Course of the Month14 days, 16 hours left to enroll

839 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