Solved

php date

Posted on 2014-01-14
17
467 Views
Last Modified: 2014-01-15
Hi i need to convert this date 2009-01-23T03:00:02-05:00 to regular standard date

Second function i searching to convert regular date time to 2009-01-23T03:00:02-05:00
0
Comment
Question by:umaxim
[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
  • 8
  • 6
  • 2
  • +1
17 Comments
 
LVL 12

Expert Comment

by:sivagnanam chandrakanth
ID: 39781346
Here is the sample

<?php
//For first question
	$date=strtotime("2009-01-23T03:00:02-05:00");
	echo date('d-m-Y',$date);
	
//for second question
	
	$lastmod = '2012-11-28 10:53:17'; //MySQL datetime format

$datetime = new DateTime($lastmod);
$result = $datetime->format('Y-m-d\TH:i:sP');

echo $result; //2012-11-28T10:53:17+01:00
?>

Open in new window

0
 
LVL 1

Author Comment

by:umaxim
ID: 39781398
it is working but it always increase time on one hour
2013-10-06T20:38:00-05:00

2013-10-06 21:38:00
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39781409
"Regular standard date" is not a term of art in computer science.  All dates are spelled out in formats that are infinitely malleable, using PHP strtotime() and date() functions.  The background information you need, as well as specific examples are available in this article.  Please read it over and if you still have questions, post back and I'll be glad to help.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
0
Industry Leaders: 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 6

Expert Comment

by:Mahesh Bhutkar
ID: 39781504
It may be your LOCALE setting issue.

Checkout with your server locale & machine locale.
0
 
LVL 12

Expert Comment

by:sivagnanam chandrakanth
ID: 39781673
the example given me works in my system.. may be 1+ hour issue is due to your server time / timezone settings
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39782143
The PHP server and the SQL server have independent timezone settings.  Your client location may also have an independent timezone (Client in New York, Server in Chicago).  There is a difference between the value of PHP time() (UNIX  Timestamp) and the local timezone.  The UNIX time is the same worldwide, whereas the local time is affected by the timezone setting.  It's a common question and it's all made clear in the Experts-Exchange article about dates and times.
0
 
LVL 1

Author Comment

by:umaxim
ID: 39782726
i read this article 2 time already and can not find the reason why my script give me 1 hour late time. I add new york zone to server and same zone to quickbooks program.  Then I add same setting to my script

// We need to make sure the correct timezone is set, or some PHP installations will complain
if (function_exists('date_default_timezone_set'))
{
      date_default_timezone_set('America/New_York');
}

I have exact same time on both servers. But still program return me extra hour
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39782737
Why are you wrapping the function call in an if() statement?

What is the value of date_default_timezone_get() or the value displayed in phpinfo():
0
 
LVL 1

Author Comment

by:umaxim
ID: 39782748
date

date/time support      enabled
"Olson" Timezone Database Version      0.system
Timezone Database      internal
Default timezone      America/New_York
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39782808
Wondering about the Timezone Database Version.  Could it be stuck in daylight savings time?  Here is what mine says:

date/time support       enabled
"Olson" Timezone Database Version       2013.8
Timezone Database       internal
Default timezone       America/Chicago
0
 
LVL 1

Author Comment

by:umaxim
ID: 39782817
i checked script it only add extra hour when
2013-10-06T20:38:00-05:00
            2013-10-06 21:38:00

and when
           
2013-12-09T11:22:20-05:00
2013-12-09 11:22:20
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39782824
The first date is during daylight savings time.  The second date is not.
0
 
LVL 1

Author Comment

by:umaxim
ID: 39782838
ok but how i can fix this kind of problem any idea ?
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39782875
Please see: http://www.laprbass.com/RAY_temp_umaxim.php

The timezone offset from GMT is the same on both date strings, but it should be an hour different when daylight saving time is in play.  That may not be the only issue, but it could be the problem.  Since the datetime string specified the exact hours of the offset, PHP probably took the value and used it "as is."

<?php // RAY_temp_umaxim.php
error_reporting(E_ALL);
echo '<pre>';

// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28338819.html

// MAKE SURE THE TIMEZONE IS SET CORRECTLY
date_default_timezone_set('America/New_york');
echo PHP_EOL . date_default_timezone_get();

// SHOW THE TIMEZONE OFFSETS FOR NOT-DST AND FOR DST
echo PHP_EOL . date('c', strtotime('Jan 1, 2013'));
echo PHP_EOL . date('c', strtotime('Jul 1, 2013'));

$date_1 = '2013-10-06T20:38:00-05:00';
$ts_1   = strtotime($date_1);

$date_2 = '2013-12-09T11:22:20-05:00';
$ts_2   = strtotime($date_2);

// CHECK DAYLIGHT SAVING TIME
echo PHP_EOL . "$date_1 SETTING FOR DST IS: " . date('I', $ts_1);
echo PHP_EOL . "$date_2 SETTING FOR DST IS: " . date('I', $ts_2);

Open in new window

HTH, ~Ray
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39782906
Run this and see what happens if the explicit timezone offset is omitted.  It may give you what you need.

<?php // RAY_temp_umaxim.php
error_reporting(E_ALL);
echo '<pre>';

// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28338819.html

// MAKE SURE THE TIMEZONE IS SET CORRECTLY
date_default_timezone_set('America/New_york');
echo PHP_EOL . date_default_timezone_get();

// SHOW THE TIMEZONE OFFSETS FOR NOT-DST AND FOR DST
echo PHP_EOL . date('c', strtotime('Jan 1, 2013'));
echo PHP_EOL . date('c', strtotime('Jul 1, 2013'));

$date_1 = '2013-10-06T20:38:00-05:00';
$ts_1   = strtotime($date_1);

$date_2 = '2013-12-09T11:22:20-05:00';
$ts_2   = strtotime($date_2);

// CHECK DAYLIGHT SAVING TIME
echo PHP_EOL . "$date_1 SETTING FOR DST IS: " . date('I', $ts_1);
echo PHP_EOL . "$date_2 SETTING FOR DST IS: " . date('I', $ts_2);

// TRY AGAIN, OMITTING THE EXPLICIT TIMEZONE OFFSET VALUE
$date_1 = '2013-10-06T20:38:00';
$ts_1   = strtotime($date_1);

$date_2 = '2013-12-09T11:22:20';
$ts_2   = strtotime($date_2);

// CHECK DAYLIGHT SAVING TIME
echo PHP_EOL . "$date_1 SETTING FOR DST IS: " . date('I', $ts_1);
echo PHP_EOL . "$date_2 SETTING FOR DST IS: " . date('I', $ts_2);

echo PHP_EOL . date('c', $ts_1);
echo PHP_EOL . date('c', $ts_2);

Open in new window

0
 
LVL 1

Author Closing Comment

by:umaxim
ID: 39783054
Thank you
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39783165
Thanks for the points, and thanks for using EE, ~Ray
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

Suggested Solutions

Title # Comments Views Activity
Session time out quickly. 6 51
Form submit takes only for one form 23 47
Link Stopped Working 7 28
foreach loop to only capture results that are greater than 0 16 36
This article discusses how to create an extensible mechanism for linked drop downs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

738 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