For all the tables in my database, with all columns with date types, in PHP I want to be able to output the correct time in my timezone (GMT) I'm also using a php function to convert the raw datetime from MySQL into a more readable format such as "1 day ago", "1 minute ago" etc..
The problem is in PhpMyAdmin, if I run the SQL Query "SELECT NOW()", I'm displayed with a time 4 hours behind my timezone, which I don't want.
For example, the time of writing is 17:03pm, but MySql returns it as 13:01pm.
So, whenever I test submit a form which posts data to the table, the record on the page shows submitted "4 hours ago" where instead it should say "x seconds ago", because the server is 4 hours behind.
The shared hosting server is configured to EST time and Namecheap hosting support said this can't be changed.
They provided me some PHP code which does return the correct time on the web page like this:
$today = date("H:i:s");
echo $today
They've also provided this way to select the correct time by itself, but ... I don't know how to assign this to the data outputted from the column inside the table, so it says "x seconds ago" instead of "4 hours ago"...
<?php
$correctTime = "SELECT date_add(now(),interval +4 hour) AS correct";
$correctTimeSQL = mysqli_query($con, $correctTime);
?>
<?php
while($row = mysqli_fetch_assoc($correctTimeSQL)){
?>
<?php echo $row['correct'];
}
?>
My column is called dateSubmitted and here is a photo of the records:
Then I output the column using PHP like this: (without the php function converting the datetime to a more readable format)
<?php echo $row['dateSubmitted'];?>
How can I get the time to display in my timezone, instead of EST, or combine it with the 4 hour interval code? Whenever I use the final code, it always is behind. Namecheap also changed the server to Europe/London.