I have a zip_code database that also has the correct time zone associated with the zip code. I store the users zip_code in a session and pull their time zone correctly like this:
$timezone_array = mysql_query("SELECT time_zone FROM zip_code WHERE zip_code = '".$zip_session."'");
while($timezone_cells = mysql_fetch_array($timezone_array))
{
$their_timezone = $timezone_cells['time_zone'];
}
if my zip code is 07110, then $their_timezone will be Eastern. How do I use this with PHP to set the correct timezone? I cant figure out a way to use this function date_default_timezone_set('America/new_york') like this date_default_timezone_set($their_timezone). the time_zones stored in the DB are Atlanic, Eastern, Central, Mountain, Pacific etc. Any function in PHP that can use these instead of nearest city ex: America/New_York?
US/Central, US/Eastern, US/Pacific are valid see:
List of Supported Timezones:Other
Related
When I try to insert a record in to the oracle using oci8 extension, I'm getting invalid month error.
'29-12-2015'
But if I try:
'29-DEC-2015'
It works. What could be the problem? And how can I solve it?
Unless you've explicitly set your session parameters you're probably using the database default date format; something like DD-MON-RR.
Check your session date formats using select * from nls_session_parameters.
To address your problem you can either:
set your session to recognise the date format you want to use:
alter session set NLS_DATE_FORMAT = ...
or explicitly convert strings to dates in the statement:
... to_date('2015-01-13', 'YYYY-MM-DD') ...
hello all i am trying to find the recent birthday of the registered members on the site and also store the result of query into session so that next time the query need not to be executed so to reduce the page load time and also server load
i am having this code
if(!isset($_SESSION['dob']) || $_SESSION['dob'] =='' ){
$frndlist=$_SESSION['friendlist']; //comma seperated list of friends
$CurrMOnth= date('m'); // this month
$BirthDLAST0n=date('d', strtotime(' - 7 day'));
$BirthDGRATEn=date('d', strtotime(' + 7 day'));
$GEttheBIrthdaYS=mysqli_query($connection,"select id,name,dob from members
where (id IN ($frndlist)) and (MONTH(dob) = '$CurrMOnth') and
(DAY(dob) > '$BirthDLAST0n' and DAY(dob) < '$BirthDGRATEn' )
order by dob desc limit 10");
$_SESSION['dob']=$GEttheBIrthdaYS;}else{
$GEttheBIrthdaYS=$_SESSION['dob'];
}
while($theBdaYSreYAr90=mysqli_fetch_array($GEttheBIrthdaYS)){ //print }
but the problem here is result of query is stored into session but it is never accepted by the mysqli_fetch_array it says error.
this is problem because i am trying to store object onto session
is there any alternative to store the result into something so that the same query need not to be executed gain again ....
and also the birthday script is not good it dosent displays the birthday of people whose DOB is at the last or begning of months.
please let me know how to store the result of query into session or cookie
as cookie stores very less size i dont think cookie is good option.
Looks like you're trying to put a whole array into the session var, just break it up.
$result = mysql_fetch_array($GettheBIrthdaYS);
$_SESSION['dob'] = $result['dob'];
Also make your limit 1, unless you want more than 1 record, which if you do then you will need to change everything.
In my database, updateTime is set to TIMESTAMP and CURRENT_TIMESTAMP. But when I display the data, the time that was recorded in the database is not my local timezone but rather 3 hours later. How can I subtract those 3 hours by converting this SQL statement? Can I use CONVERT_TZ somehow inline with this statement? I don't know how to do it.
SELECT updates.updateID, updates.windowStatus, updates.onDeck, updates.updateComments, TIME_FORMAT(`updateTime`,'%r') AS showtime FROM updates ORDER BY updates.updateID DESC LIMIT 1
The Server Time Zone can be set by each client (per-connection) in order to receive the data in other TZ than UTC. In order to do that, you just have to use:
SET time_zone = timezone;
The value of timezone can be given as an offset of UTC ('+10:00', '-6:00', ...) or as a named time zone (such as 'Europe/Helsinki', 'US/Eastern', or 'MET'). Therefore, you can set your own TZ in order to receive your data in '+3:00', if I'm not mistaken.
Take into account that this offset done by the mysql server only affects NOW(), CURTIME() and values stored in and retrieved from TIMESTAMP columns (which is what you're looking for).
You could otherwise use
SELECT ##global.time_zone, ##session.time_zone;
to get the global and client-specific timezones.
There's more relevant info (and this is actually a sum-up of what I wrote) at: Time-zone support (mysql.com).
In your case, you could have something like this:
<?php
mysql_select_db($database_casualconnnect, $casualconnnect);
$set_tz_query = "SET time_zone = '+1:00'";
mysql_query($set_tz_query, $casualconnnect) or die(mysql_error());
$query_Recordset2 = "SELECT updates.updateID, updates.windowStatus,
TIME_FORMAT(`updateTime`,'%r') AS showtime, updates.onDeck, updates.updateComments
FROM updates ORDER BY updates.updateID DESC LIMIT 1";
$Recordset2 = mysql_query($query_Recordset2, $casualconnnect) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2); $totalRows_Recordset2 = mysql_num_rows($Recordset2);
?>
I am creating a website for a church and in the events section of the code i have this
$page_contents = mysql_query("SELECT * FROM events WHERE id = '$page_content'");
$contents = mysql_fetch_array($page_contents)or die (mysql_error());
echo "<Script>alert(".$contents['date'].")</script>";
I have 3 entries in the database and the dates are 0000-00-00, 2013-06-14 & 2013-06-19
The $page_content is the $_GET page id this comes through as events/$1/ and changes through .htacess to events.php?page=$1
when date 2013-06-14 is called the above echo script gives out 1993 and when date 2013-06-19 is called i get 1988
I have none of these years in my database or anything representing these in my code ? this has completely baffled me ????
Your output is not a string since you're missing the quotes in the Javascript you're outputting. It actually looks like this:
alert(2013-06-14)
Yeah, those are numbers, which are being subtracted...
this code is not working why :(
$id = $temp['curchar'];
$data=strtotime(date('Y-m-d H:i:s'))+30; //+30 seconds to unix time
mysql_query("UPDATE `chars` SET data='$data' WHERE id='$id'");
Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in C:\Program Files\WebServ\httpd\world_1\char_info_slow.php on line 23
too many questions, you probably can start by checking
how you connect to mysql?
what is the column type for data?
is $id match any record in table?
how to verify are the matched records get updated?
if your account connect to mysql allow to do write?
ps:
$data=strtotime(date('Y-m-d H:i:s'))+30; <-- wordless ...
$data = time()+30;
pps:
at least, you should try
$sql = "UPDATE `chars` SET data='$data' WHERE id='$id'";
mysql_query($sql) or trigger_error(mysql_error()." in ".$sql);
There's no reason to generate a date in PHP just to do some date arithmetic in MySQL. You can do this far easier within mysql as is:
UPDATE chars
SET data=DATE_ADD(data, INVERVAL 30 SECOND)
WHERE id=$id
Of course, this assumes you've made data a datetime type field. If it's just an int, then why bother with all the date math, and just do data=data+30.
As well, you're generating your time value in a highly inefficient manner. You format the current date as a string, convert that string to a number, and add 30 to it. Why not just do
$data = time() + 30;
instead? time returns the current date/time as a single integer (a unix timestamp), saving you the round trip through String Land.