PHP - Date() Function Returns Wrong Time
I think it is unusual but i dont know to fix it. when my computer clock shows 16: 13 hours , date() reuturns 10:43:16 . My systems time zone is +5.30 GMT.
how does date() subtracts 5.30 hrs from the system time? Similar TutorialsFirst, I would like to say when i tried to recover my account from this website, I took me 10 attempts to get the captcha right and then finally it said it sent me an email to my gmail account. I checked spam folder and everything there was no such email from this site. Then I decided to create a new account, well, it took me another 10 attempts to get the captcha right and finally when it was submitted, the page was loading for around 3 minutes before it signed me in.
My question is about the php date() function. It accepts a format to display a time. In the following example I use F for full representation of month, d for 2-digit day of month with leading zeros, Y for full year, g for 12-hour format without leading 0s, s for seconds and A for meridiem. It uses the correct format, but it gives me the wrong time. My local time is 4:43 and it prints out 4:12:
<?php echo "<p>order processed on " . date("F d, Y g:sA") . "</p>"; ?> Why is it 30 minutes behind? I need to know which day of week was on particular date, so for example I would provide date lets say "Nov 22, 2010" formatted as needed and the function would return "Monday", is there a function in php to do that or how can it be done? PHP date and time function is not showing correct time on my local system I have the following php code date_default_timezone_set("Africa/Lagos"); $date = date('d-m-y h:i:s'); echo "Server Time ".$date ."<br>"; echo "The time is " . date("h:i:sa")."<br>"; $current_datetime = date("Y-m-d") . ' ' . date("H:i:s", STRTOTIME(date('h:i:sa'))); echo "Current time1: ".$current_datetime . "<br>";
Output
Server Time 21-05-21 09:55:39
Expected Output
Server Time 21-05-21 10:55:39
Any help would be appreciated. Edited May 21 by Ponel Hi there, what I have been trying to do is add some additional logic.. My problem is I want to stop displaying the month and day after the year 2000? I know I need to add an if and else statement but this is my first actual project and I am a little stuck.. here is the page, it's a plugin for a timeline http://www.llandover...oject-timeline/
And the file is attached below.. any help would be appreciated. The plugin code was too long to just post in here, didn't want to cause any slow loading issues for people on a slow connection.. Thanks and I appreciate any help.
Attached Files
annual_archive.php 18.15KB
5 downloads hello i got this small function i`m working on to get the date of a month something like get current date - 1 but not sure how to handle jan month can someone help me please ? $month = date('m') - 1; $date_startt = date('Y').'-'.$luna.'-01'; $timestamp_start = strtotime($data_start);
Question:
Background:
Example: The Pacific ("Los Angeles") time right now is 7:58pm, but my code says it's 6:58pm. So now I have to go in and correct the "PT8H" portion. I'm wondering if there is some code I can use whereby I can simply "set it and forget it." Thank you! Edited May 2, 2020 by StevenOliverHey guys, How would I go about subtracting Today from a previous day to find the difference? For example, I want to subtract TODAY from a previous date in my database, to determine if the difference is greater than 1 day. Any ideas? I tried doing the subraction in TIMESTAMPS, but when I convert the date back to Y-m-d H:i:s, I got some weird year and time. I have a table korisnici in SQLite with INTEGER field aktivan that can have only 0 or 1 value (CHECK constraint). Field aktivan has value 0 but PHP returns value 1, why? Is this a bug? This is PHP code that I am running: $sql = "SELECT ime, aktivan FROM korisnici WHERE lower(ime) = '" . $ime . "'" . " AND sifra = '" . $_POST["sifra"] . "'"; $result = $db->query($sql); $row = $result->fetchArray(SQLITE3_ASSOC); $row['aktivan'] = 1 but in table the value is 0. When I run same query in DB Browser for SQLite I get correct value 0. Is this a bug? I am trying to simulate an ad expiration and carry out an action if the ad is expired. And I cannot get the if/else to work properly... I've tried many variations and I cannot see what I am doing wrong here. Any tips please 3 hours and counting of no solution! $ad_start = time()-14 . "<br />"; // 14 days from today in the past (negative) echo $ad_start; $current_time = time() . "<br />"; // current epoch time echo $current_time; $days_past = $ad_start - $current_time; // days past echo "<br />$days_past days have past since the ad started!<br />"; if($days_past <= 14) { echo "<br />Ad is less than 14 days. Not expired."; } else { echo "<br />Ad is over 14 days. Expired."; } Alright, I have a Datetime field in my database which I'm trying to store information in. Here is my code to get my Datetime, however it's returning to me the wrong date. It's returning: 1969-12-31 19:00:00 $mysqldate = date( 'Y-m-d H:i:s', $phpdate ); $phpdate = strtotime( $mysqldate ); echo $mysqldate; Is there something wrong with it? I have this: $sql = mysqli_query($conn, "SELECT ip , page , CASE WHEN referrer = '' THEN 'N/A' ELSE referrer END as referrer , DATE_FORMAT(date, '%m/%d/%y') as date , TIME_FORMAT(time, '%T') as time FROM tblTraffic ORDER BY date DESC, time DESC"); most of my traffic report contains the correct times, my time, which is CST in the USA. but some records are off by a lot. Does the time() function capture the time of the actual location from which the visitor is coming from? if so, what could I do to return my timezone for any visitor? w3 schools and php.net don't mention this. I am having a problem with PHP displaying the correct date and time. It updates as it should, but is fast by 4min and is always displaying a date in 2004. I ran a basic php script to make sure the application im using itself is not wrong. go to lunenburgledger.com/time.php Anybody had any ideas on where to check? The system time on the Windows Server 2003 is correct. The only thing I can think of is that it was converted to a virtual machine on vmware esxi, but the system time stayed right. Any ideas? Thanks! OK So I've got a datepicker that sends a date in d/m/y format. My DB stores the data in Unix Timestamp Which I can convert the date to with strtotime however this does the exact date & time. All I want is the actual day. I've spent hours trying to convert this with just the day with mixed results... Thanks. Hi! For all my queries I use safe_query() and this function returns mysql_query() Now I want to count how many queries is being returned in this function... can someone modify the code and assign a variable to return max returns please? I would be grateful, thanks! Code: [Select] // -- MYSQL QUERY FUNCTION -- // $_mysql_querys = array(); function safe_query($query="") { global $_mysql_querys; if(stristr(str_replace(' ', '', $query), "unionselect")===FALSE AND stristr(str_replace(' ', '', $query), "union(select")===FALSE){ $_mysql_querys[] = $query; if(empty($query)) return false; if(DEBUG == "OFF") $result = mysql_query($query) or die('Query failed!'); else { $result = mysql_query($query) or die('Query failed: ' .'<li>errorno='.mysql_errno() .'<li>error='.mysql_error() .'<li>query='.$query); } return $result; } else die(); } Hello I am on to OOP now and I dont know how to write the syntax to print the results I want The scenario is I have the abstract class, its subclass and then the object that calls the subclass, all in different files. So: part of the subclass reads: Code: [Select] function __construct($v1, $v2, $v3) { $this->speed[] = $v1; // I dont like this either, it is not elegant. I tried to put an array as argument of the constructor and send the parameters $this->speed[] = $v2; // from the object being created, but it did not work, so I leave it like this for now, but I would have preferred to put that $this->speed[] = $v3; // array and then populate it by some looping. } // METHOD TO REPORT TABLE OF ACCELERATION public function acceleration() { return $this->acceleration1 = ($this->speed[1] - $this->speed[0])/5; // I actually need to return the other two speed differences from the other stages, but as you know, once the first return acts, it exits the function // so sure this "return" has to be abandoned and the results of the function have to be printed otherwise. That is the question. } =================================== And now from the Object file I am trying to call the function, but of course, I only get one value, even if I write 3 times return Code: [Select] $objeto = new Motorbike($v1, $v2, $v3); echo '<p>The speeds are ' . $objeto->acceleration() . '</p>'; // Yes, this call works, of course, but that is about it. I cant print any other result. Thanks a lot How can I check if a function has returned false.. I know theirs the following way: if (!checkdate($month, $day, $year)) { //the function has returned false } But is their another way (beside using the ! operator) perhaps === FALSE (not sure if that'd work so asking)? ok so this problem has been laughing at me for quite some time now I tryed using some inline php in a form to pass it to my login script. The problem is that whenever the form gets submitted the variable r doesn't contain the actual microtime but it contains the inline php as a string: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Snitch</title> <link rel="stylesheet" type="text/css" href="templates/css/snitch1440x900.css" /> </head> <body> <div id="login-achtergrond"> <div id="login"> <form action="." id="loginform" name="login" method="post"> <input type="hidden" name="actie" value="Login"></input> <input type="hidden" name="r" value="<?php echo microtime();?>"></input> <input type="text" id="gebruikersnaam" name="gebruikersnaam" value="" style="opacity:0.7;filter:alpha(opacity=70)"></input> <input type="password" id="paswoord" name="paswoord" value="" style="opacity:0.7;filter:alpha(opacity=70)"></input> <input id="aanmelden" type="submit" name="submit" value="" style="opacity:0;filter:alpha(opacity=0)"> </form> </div> <div id="registreer"> </div> </div> </body> </html> the $_POST['r']; contains "<?php echo microtime();?>" instead of for example: 0.53192500 1305636839 does someone know what I am doing wrong here? I also tryed doing it like this: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Snitch</title> <link rel="stylesheet" type="text/css" href="templates/css/snitch1440x900.css" /> </head> <body> <div id="login-achtergrond"> <div id="login"> <form action=".r=<?php echo microtime();?>" id="loginform" name="login" method="post"> <input type="hidden" name="actie" value="Login"></input> <input type="text" id="gebruikersnaam" name="gebruikersnaam" value="" style="opacity:0.7;filter:alpha(opacity=70)"></input> <input type="password" id="paswoord" name="paswoord" value="" style="opacity:0.7;filter:alpha(opacity=70)"></input> <input id="aanmelden" type="submit" name="submit" value="" style="opacity:0;filter:alpha(opacity=0)"> </form> </div> <div id="registreer"> </div> </div> </body> </html> both $_POST and $_GET contains a string instead of the actual microtime single quotes didn't work eather can anyone see the problem here i am running php 5.3 on my server and GD seems to be enabled. and my host said it was probably something to do with the captcha files or script. <?php session_start(); /* * File: CaptchaSecurityImages.php * Author: Simon Jarvis * Copyright: 2006 Simon Jarvis * Date: 03/08/06 * Updated: 2007-08-12 by Jenny Ferenc (minor visual changes only) * Requirements: PHP 4/5 with GD and FreeType libraries * Link: http://www.white-hat-web-design.co.uk/articles/php-captcha.php * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * http://www.gnu.org/licenses/gpl.html * */ class CaptchaSecurityImages { var $font = 'VeraSe.ttf'; function generateCode($characters) { /* list all possible characters, similar looking characters and vowels have been removed */ $possible = '23456789bcdfghjkmnpqrstvwxyz'; $code = ''; $i = 0; while ($i < $characters) { $code .= substr($possible, mt_rand(0, strlen($possible)-1), 1); $i++; } return $code; } function CaptchaSecurityImages($width=130, $height=40, $characters=6) { $code = $this->generateCode($characters); // font size will be 60% of the image height $font_size = $height * 0.6; $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream'); // set the colours $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 20, 40, 100); $noise_color = imagecolorallocate($image, 100, 120, 180); // generate random dots in background for( $i=0; $i<($width*$height)/3; $i++ ) { imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color); } // generate random lines in background for( $i=0; $i<($width*$height)/150; $i++ ) { imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color); } // create textbox and add text $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4])/2; $y = ($height - $textbox[5])/2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function'); // output captcha image to browser header('Content-Type: image/jpeg'); imagejpeg($image); imagedestroy($image); $_SESSION['security_code'] = $code; } } $captcha = new CaptchaSecurityImages(); ?> this seems to be the problem line he Code: [Select] $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function'); [\code] I have a MySQL column which holds the date in DATETIME format. When I pull it and try and format it in php using the DATE function the times are wrong. See code below: <?php print date("d/m/y @ G:H:s A", strtotime($pt->transaction_date)); ?> Anyone know why this is the case ? I'm getting this Time Zone error. Perhaps it's a compatibility issue with PHP 5.3. Looked all over for an answer without finding one. Here is the error message Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EST/-5.0/no DST' instead in /blocked.php on line 41 12/02/12 Here is the code. Line 41 is near the bottom, the one with the d,m,y. Perhaps the echo date (d/m/y") needs to be changed. Appreciate any help! Code: [Select] <table border="3" width="16%" align="center" cellspacing="0" bgcolor="#FF6600" bordercolor="red" bordercolordark="red" bordercolorlight="red"> <tr> <td width="176"> <p align="center"><?php // shows IP Number on Page echo $ip; ?> </p> </td> </tr> </table> <p align="center"><?php // Show the user agent echo 'Your user agent is: <b>'.$_SERVER['HTTP_USER_AGENT'].'</b><br />';?></p> [b]<h1 align="center"><?php echo date("d/m/y");?></h1>[/b] </td> </tr> </table [,code] |