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;
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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

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
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

MarkProgrammerAuthor Commented:
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"

<title>PHP MySQL Time test</title>
<h1>PHP MySQL Time test</h1>
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>";
// 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>";


Open in new window

MarkProgrammerAuthor Commented:
K, thanks
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

From novice to tech pro — start learning today.