Solved

cut seconds and UTC from time

Posted on 2013-06-26
6
237 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 167 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 166 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 109

Accepted Solution

by:
Ray Paseur earned 167 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

785 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