Click here to Skip to main content
15,900,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey guys i live in south africa and every time i insert the time to my database it gives me 1hour behind current time i think it is because of daylight savings can you help me fix this source below.

PHP
<?php

include("connect.php");
include("Includes/view.php");

session_start();

if( !isset($_SESSION['id']))
{
    header('Location: ../index.php');
}

$name = $_SESSION['name'];
$queue = $_POST['queue'];
//$TarosID = $_POST['TarosID'];
//$Status = $_POST['Status'];
//$Reason = $_POST['Reason'];

$date = date("Y/m/d");
$time = date("H:i:s");

$query = "INSERT INTO sms_traffic_db.table_data (name, date, time, queue) VALUES ('".$name."', '".$date."','". $time."', '".$queue."')";
$result = mysql_query($query) or mysql_error();
if($result)
{
    header('Location: ../main.php');
    echo "Data Inserted successfully";
}
else
{
    header('Location: ../add_entry.php');
    echo "Error" .mysql_error();
}
echo '<p>'.$query.'</p>';

mysql_close();

?>
Posted
Updated 5-Nov-13 22:54pm
v3

1 solution

You should be storing dates and times as UTC as DATE, DATETIME or TIMESTAMP types[^], not as strings, as this always causes problems when converting. You can get the current UTC time with the time()[^] function.
 
Share this answer
 
Comments
Joezer BH 7-Nov-13 1:01am    
5ed!
Richard MacCutchan 7-Nov-13 5:00am    
:thumbsup:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900