Solved

cut seconds and UTC from time

Posted on 2013-06-26
6
241 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
[X]
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
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
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 
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 110

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
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 …

729 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