Jump to content

How to change the timezone after pulling data from MySQL?


jalpro

Recommended Posts

I have a news table set up in MySQL.

 

My PHP code reads the date&time from the database using the following code:

$date=$rows["NewsDate"];

And prints it to html using:

echo "<td id=newsdate>$date</td></tr>";

(it's part of a table)

 

That all works fine.

 

In order to get data into the database, I simply use PHPmyAdmin to do so.

I use the NOW() function to get the current time and date automatically.

 

However, because I am in the UK, the time is out by 8 hours.

 

I have tried putting the following line into the .htaccess file in the same directory as the html file that is reading the database:

SetEnv TZ Europe/London

...but that didn't do anything.

 

Help!

Thanks :)

Link to comment
Share on other sites

I have tried putting the following line into the .htaccess file in the same directory as the html file that is reading the database:

SetEnv TZ Europe/London

...but that didn't do anything.

 

Well it did actually do something but it didn't help your MySQL dates. What you did was change the date and time on your site when using php date(). As far as changing it for MySQL I can't help you but I'm sure somebody else can. :)

Link to comment
Share on other sites

Actually you are right.

I did a test with:

<?php
echo date('d-m-Y H:i:s');
?>

...and the time was correct.

 

Instead of writing my news straight into PHPmyAdmin, if I created a php page/form to write the news to the database, would I need to alter the code to add on 8 hours or will the .htaccess modification do that for me?

 

Thanks :)

 

~~~~~UPDATE~~~~~~

 

Okay so I made that php page.

I get the date using:

$date=date('Y-m-d H:i:s');

That works.

 

But now I have two other problems:

  1. The time is 7 minutes out.
  2. Sometimes I need to change the content of the post. And the only way I can do that with the current setup is through PMA. Once I've changed the content, I like to update the time, but if I choose NOW(), it reverts back to being 8 hours out.
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...