Link to home
Start Free TrialLog in
Avatar of umaxim
umaximFlag for United States of America

asked on

php date

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
Avatar of sivagnanam chandrakanth
sivagnanam chandrakanth
Flag of India image

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

Avatar of umaxim

ASKER

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

2013-10-06 21:38:00
"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.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
Avatar of Mahesh Bhutkar
Mahesh Bhutkar

It may be your LOCALE setting issue.

Checkout with your server locale & machine locale.
the example given me works in my system.. may be 1+ hour issue is due to your server time / timezone settings
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.
Avatar of umaxim

ASKER

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
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():
Avatar of umaxim

ASKER

date

date/time support      enabled
"Olson" Timezone Database Version      0.system
Timezone Database      internal
Default timezone      America/New_York
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
Avatar of umaxim

ASKER

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
The first date is during daylight savings time.  The second date is not.
Avatar of umaxim

ASKER

ok but how i can fix this kind of problem any idea ?
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
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of umaxim

ASKER

Thank you
Thanks for the points, and thanks for using EE, ~Ray