Link to home
Create AccountLog in
Avatar of curiouswebster
curiouswebsterFlag for United States of America

asked on

PHP: getting local time

In this Prepared Statement, I have trouble getting localtime.

Previously, I saw a PHP function that let me insert 'localtime'

$smt->bindValue(':create_date', date("Y-m-d h:i:s"), SQLITE3_TEXT);

Suggestions?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of David Favor
David Favor
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of curiouswebster

ASKER

The time is not coming back local (EST), it's coming back off by one time zone. Here's why...
User generated image
So,I need the attribute for localtime.

Here is the Prepared Statement, which seems to be adding new records without errors:
$smt = $db->prepare("insert into  contacts (statusid, fname, lname, street, city, state, zip, title, company, voterid, create_date, update_date) values (:statusid, :fname, :lname, :street, :city, :state, :zip, :title, :company, :voterid, :create_date, :update_date)");
$smt->bindValue(':statusid', 5, SQLITE3_INTEGER); // statusId of 5 == "Pending"
$smt->bindValue(':fname', $_GET['fname'], SQLITE3_TEXT);
$smt->bindValue(':lname', $_GET['lname'], SQLITE3_TEXT);
$smt->bindValue(':street', $_GET['street'], SQLITE3_TEXT);
$smt->bindValue(':city', $_GET['city'], SQLITE3_TEXT);
$smt->bindValue(':state', $_GET['state'], SQLITE3_TEXT);
$smt->bindValue(':zip', $_GET['zip'], SQLITE3_TEXT);
$smt->bindValue(':title', $_GET['title'], SQLITE3_TEXT);
$smt->bindValue(':company', $_GET['company'], SQLITE3_TEXT);
$smt->bindValue(':voterid', $_GET['vid'], SQLITE3_TEXT);
$smt->bindValue(':create_date', date("Y-m-d h:i:s"), SQLITE3_TEXT);
$smt->bindValue(':update_date', date("Y-m-d h:i:s"), SQLITE3_TEXT);


$result = $smt->execute();
var_dump($result->fetchArray(SQLITE3_ASSOC));
$smt->close();
$db->close();
$db=null;

Open in new window


I guess localtime is not what I want. I want to explicitly ask for EST or, more correctly, EDT.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Does this call:
date_default_timezone_set("America/New_York");

also set the page, when I use DateTime objects?
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
This code crashes my page:

$date = new DateTime(null, new DateTimeZone('America/New_York'));
echo $date->format('Y-m-d H:i:s') . "\n"


$date = new DateTime('2000-01-01'); // WORKS
echo $date->format('Y-m-d H:i:sP') . "\n";

$date = new DateTime(null, new DateTimeZone('America/New_York')); // FAILS
echo $date->format('Y-m-d H:i:s') . "\n"

What am I missing?
You know what, Scott? After reading your post. I probably should use UTC for all data INSERT and UPDATE calls, and use local time for the UI. So, I presume I would set the config.php to be UTC. Then, when displaying the current time (if I ever needed to) I would display localtime.

Make sense?
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.