Solved

cut seconds and UTC from time

Posted on 2013-06-26
6
233 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 82

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 108

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
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 …

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now