Does PHP DateTime function and MySQL's convert_tz automatically factor in daylight savings time?

PHP sample code:
			
$newts = new DateTime($string, new DateTimeZone($fromTimeZone) );
$newts->setTimeZone(new DateTimeZone($toTimeZone));
$finalts = $newts->format($oformat);

Open in new window


MySQL sample code:
SELECT tz_convert(`colname`, ......) AS converted_datetime FROM table;
MarkProgrammerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michael DyerSenior Systems Support AnalystCommented:
It should read the current date and time from the local server, so if that is set up for DST, you should be good.
0
MarkProgrammerAuthor Commented:
What do you mean setup for DST?

In some instances I need the current time and in some I need to pass a pre-stored UTC datetime and have it converted a new timezone ..

I just want to make sure that the functions I am using in either PHP and MySQL factors in DST when converting time...
0
Ray PaseurCommented:
I am fairly certain that PHP gets this right.  DST is a function of the timezone in effect at the time you call the relevant PHP functions or methods.  If you give PHP a Unix timestamp and ask PHP to render the date/time value in a given timezone, you're on firm ground.  I have never tested this with MySQL, but this article shows the (procedural) PHP and MySQL way of doing things.  I think it would be easy to set up a test on your server.  See "Leap Year and Daylight Savings Time" and "PHP and MySQL Have Different Time Zone Settings" in this article.  You might consider keeping the database in UTC.
http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

MarkProgrammerAuthor Commented:
Thanks
0
Dave BaldwinFixer of ProblemsCommented:
Because I had a mismatch between PHP and MySQL on a server, I wrote this little program to check to see if they were different.  You will need to put in your own MySQL connection and details to make it work.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>PHP MySQL Time test</title>
</head>
<body>
<h1>PHP MySQL Time test</h1>
<?php 
//date_default_timezone_set('America/Chicago');
if (date_default_timezone_get()) {
    echo 'date_default_timezone_set: ' . date_default_timezone_get() . '<br />';
}

$Myoid = date("Ymd-His");
echo "PHP date and time: ".$Myoid."<br>";
include_once("dbi.php");
// check session id value from previous page	
$sql = "SELECT NOW() as dnow";
if (!$res = $link->query($sql))  die('Error83: ' . $link->connect_errno);
$cart = $res->fetch_assoc();
echo "MySQL date and time: ".trim($cart['dnow'])."<br>";

 ?>
</body>
</html>

Open in new window

1
MarkProgrammerAuthor Commented:
K, thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.