Hi,
I am trying to add the current time to a database using a PDO statement and curtime(). The time being sent to the database is 7 hours behind my current time in central Europe at CET.
So either I need to change the timezone setting or simply add 7 hours to it.
$sql = 'INSERT INTO notes SET
userid = :studentid
, courseid = :courseid
, date = CURDATE()
, time = CURTIME() + '7:00''
$s = $pdo->prepare($sql);
$s->bindParam(':studentid', $studentid);
$s->bindParam(':courseid', $courseid);
$s->bindParam(':time', $time);
$s->execute();
endif;
}
This doesn’t work,
, time = ADDTIME(CURTIME(), '02:00:00.000000')
This sets the time to 00:00:00
, time = CURTIME() + 3600
The following does seem to increase the time by 7 mins
, time = CURTIME() - 7
But this,
, time = CURTIME() - 60
sets it to 00:00:00
How should I proceed with this?
Thanks,
Shane
I am currently checking out
Drummin
November 27, 2014, 2:40am
3
You might need to use min:sec or 07:00 Not sure
You could try:
UTC_TIMESTAMP()
and then add 1 hour to that
Is the MySQL server that you’re using a shared one (do you have full admin privileges for it, if so you could change the default timezone
Hi,
Yes a shared server.
Thanks,
Shane
Hi,
In my index.php file I defined the timezone just after connecting to the db.
if (isset($_GET['addnotes']))
{
//echo "<pre>";
//print_r($_POST);
//echo "</pre>";
define('TIMEZONE', 'Europe/Zurich');
include $_SERVER['DOCUMENT_ROOT'] . '/artgibney/includes/db.inc.php';
try
{
foreach($_POST['student'] as $key => $studentID)
{
if(isset($_POST['attend']) && array_key_exists($key,$_POST['attend']) ||
isset($_POST['equip']) && array_key_exists($key,$_POST['equip']) ||
isset($_POST['effort']) && array_key_exists($key,$_POST['effort']) && $_POST['effort'][$key] != 0 ||
!empty($_POST['comment'][$key])):
$studentid = $_POST['student'][$key];
$courseid = $_POST['course'][$key];
$absence = (isset($_POST['attend']) && array_key_exists($key,$_POST['attend']) && $_POST['attend'][$key] == "absence" ? '1' : '0');
$late = (isset($_POST['attend']) && array_key_exists($key,$_POST['attend']) && $_POST['attend'][$key] == "late" ? '1' : '0');
$equip = (isset($_POST['equip']) && array_key_exists($key,$_POST['equip']) ? '1' : '0');
$effort = (isset($_POST['effort']) && array_key_exists($key,$_POST['effort']) ? $_POST['effort'][$key] : '0');
$comment = $_POST['comment'][$key];
$sql = 'INSERT INTO notes SET
userid = :studentid
, courseid = :courseid
, date = CURDATE()
, time = CURTIME()
, late = :late
, absence = :absence
, effort = :effort
, comment = :comment
, equip = :equip';
$s = $pdo->prepare($sql);
$s->bindParam(':studentid', $studentid);
$s->bindParam(':courseid', $courseid);
$s->bindParam(':absence', $absence);
$s->bindParam(':late', $late);
$s->bindParam(':equip', $equip);
$s->bindParam(':effort', $effort);
$s->bindParam(':comment', $comment);
$s->execute();
endif;
}
}
catch (PDOException $e)
{
$error = 'Error adding submitted daily notes data. Click the back button to continue.';
include 'error.html.php';
exit();
}
header('Location: .');
exit();
}
And also in the db access file db.inc.php I added 1 hour to GMT.
<?php
try
{
$pdo = new PDO('mysql:host=localhost;dbname=**************', '**************', '**************');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec('SET NAMES "utf8"');
$pdo->exec("SET time_zone='+01:00';");
}
catch (PDOException $e)
{
$error = 'Unable to connect to the database server.';
include 'error.html.php';
exit();
}
In the db the time is now showing as 00:00:00
Thanks,
Shane
Actually it is working now. Perhaps it needed time to rest or soemthing.
But the date and time are now correct for this timezone.
Thanks,
Shane
system
Closed
February 27, 2015, 4:09am
8
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.