Solved

php date

Posted on 2014-01-14
17
462 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
  • 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 108

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
 
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 108

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 108

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 108

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 108

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 108

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 108

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 108

Expert Comment

by:Ray Paseur
ID: 39783165
Thanks for the points, and thanks for using EE, ~Ray
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP_POST() error message 9 40
mysqli 3 18
echo time from sql to input type="time" 9 17
How to convert my query to the proper format? 5 15
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

929 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

14 Experts available now in Live!

Get 1:1 Help Now