PHP - Determining Daylight Savings Time
I'm using a time stamp where I'm getting the date and time from the database server rather than using a unix time stamp. Because I'm in a different time zone as the server, my time was always off by 1 hour. I fixed that problem by writing some code to adjust the hour of the time and the date depending on what time it was. It was working fine until a few weeks ago when I had to adjust my clock for daylight savings time... now the time is off by 2 hours because of that. Well, I fixed that and now it's working fine again. My question is does anyone know of a way to automatically determine whether or not I should be in daylight savings time or not so I can just use an if/else statement to keep the time adjusted properly rather than having to do it manually every time the time changes? Basically, I would like to do it something like the following:
Code: [Select] <?php if ($daylightsavings = "y") { (adjust time/date for 1 hour difference); } else { (adjust time/date for 2 hour difference); } ?> Anyone have any ideas? Similar TutorialsI wrote this bit of code to get the next six datetimes of a certain date. It was working perfectly until this week. Code: [Select] <?php $start = "2011-11-06"; $num_days = 6; for ($i = 0; $i <= $num_days; $i += 1) { $stamp = strtotime($start) + ($i * 86400); echo date('l - n/d/Y - h:i a',$stamp)."<br/>"; } ?> The 2011-11-06 is a Sunday so i would expect to get the following: Sunday - 11/06/2011 - 12:00 am Monday - 11/07/2011 - 12:00 am Tuesday - 11/08/2011 - 12:00 am Wednesday - 11/09/2011 - 12:00 am Thursday - 11/10/2011 - 12:00 am Friday - 11/11/2011 - 12:00 am Saturday - 11/12/2011 - 12:00 am instead it is producing: Sunday - 11/06/2011 - 12:00 am Sunday - 11/06/2011 - 11:00 pm Monday - 11/07/2011 - 11:00 pm Tuesday - 11/08/2011 - 11:00 pm Wednesday - 11/09/2011 - 11:00 pm Thursday - 11/10/2011 - 11:00 pm Friday - 11/11/2011 - 11:00 pm How should i go about fixing this so it doesn't happen again? Hey everyone,
So I've been using this code for a while and it may not be the best way of doing things but its worked for me based on my very limited knowledge of PHP. The code is based for a radio station which makes an image change based on the day and time. For some reason though due to daylight savings time ending the code is now off an hour. Whats the best way of fixing this without changing every single number? (Which I actually did try and still seem to be screwing it up) Below is the code:
<p> <?php $h = date('G'); //set variable $h to the hour of the day $d = date('w'); //set variable $d to the day of the week. $year = date('Y'); //set variable $year to the current year // SUNDAY SCHEDULE if ($d == 0 && $h >= 4 && $h < 5) $img = '/images/shows/HughHewitt.png'; else if ($d == 0 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 0 && $h >= 10 && $h < 11) $img = '/images/shows/MomTalk.png'; else if ($d == 0 && $h >= 11 && $h < 12) $img = '/images/shows/GoodParenting.png'; else if ($d == 0 && $h >= 12 && $h < 14) $img = '/images/shows/PetShow.png'; else if ($d == 0 && $h >= 14 && $h < 15) $img = '/images/shows/GardenRebel.png'; else if ($d == 0 && $h >= 15 && $h < 16) $img = '/images/shows/WorkingMother.png'; else if ($d == 0 && $h >= 16 && $h < 17) $img = '/images/shows/WhatsCooking.png'; else if ($d == 0 && $h >= 17 && $h < 18) $img = '/images/shows/HomeWizards.png'; else if ($d == 0 && $h >= 18 && $h < 19) $img = '/images/shows/DougStephan.png'; else if ($d == 0 && $h >= 19 && $h < 20) $img = '/images/shows/Finance.png'; else if ($d == 0 && $h >= 20 && $h < 21) $img = '/images/shows/PopularScience.png'; else if ($d == 0 && $h >= 21 && $h < 22) $img = '/images/shows/ABCRadio.png'; else if ($d == 0 && $h >= 22) $img = '/images/shows/Medicine.png'; else if ($d == 1 && $h >= 0 && $h < 3) $img = '/images/shows/ArmedAmerica.png'; else if ($d == 1 && $h >= 3 && $h < 4) $img = '/images/shows/HughHewitt.png'; // MONDAY SCHEDULE if ($d == 1 && $h >= 4 && $h < 5) $img = '/images/shows/HughHewitt.png'; else if ($d == 1 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 1 && $h >= 10 && $h < 13) $img = '/images/shows/BobRick.png'; else if ($d == 1 && $h >= 13 && $h < 16) $img = '/images/shows/DougStephan.png'; else if ($d == 1 && $h >= 16 && $h < 19) $img = '/images/shows/MariluHenner.png'; else if ($d == 1 && $h >= 19 && $h < 20) $img = '/images/shows/DebbieNigro.png'; else if ($d == 1 && $h >= 20 && $h < 22) $img = '/images/shows/DaveRamsey.png'; else if ($d == 1 && $h >= 22) $img = '/images/shows/JoyBrowne.png'; else if ($d == 2 && $h >= 0 && $h < 1) $img = '/images/shows/ShannonJoy.png'; else if ($d == 2 && $h >= 1 && $h < 2) $img = '/images/shows/BillNojay.png'; else if ($d == 2 && $h >= 2 && $h < 4) $img = '/images/shows/DennisPrager.png'; // TUESDAY SCHEDULE if ($d == 2 && $h >= 4 && $h < 5) $img = '/images/shows/DennisPrager.png'; else if ($d == 2 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 2 && $h >= 10 && $h < 13) $img = '/images/shows/BobRick.png'; else if ($d == 2 && $h >= 13 && $h < 16) $img = '/images/shows/DougStephan.png'; else if ($d == 2 && $h >= 16 && $h < 19) $img = '/images/shows/MariluHenner.png'; else if ($d == 2 && $h >= 19 && $h < 20) $img = '/images/shows/DebbieNigro.png'; else if ($d == 2 && $h >= 20 && $h < 22) $img = '/images/shows/DaveRamsey.png'; else if ($d == 2 && $h >= 22) $img = '/images/shows/JoyBrowne.png'; else if ($d == 3 && $h >= 0 && $h < 1) $img = '/images/shows/ShannonJoy.png'; else if ($d == 3 && $h >= 1 && $h < 2) $img = '/images/shows/BillNojay.png'; else if ($d == 3 && $h >= 2 && $h < 4) $img = '/images/shows/DennisPrager.png'; // WEDNESDAY SCHEDULE if ($d == 3 && $h >= 4 && $h < 5) $img = '/images/shows/DennisPrager.png'; else if ($d == 3 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 3 && $h >= 10 && $h < 13) $img = '/images/shows/BobRick.png'; else if ($d == 3 && $h >= 13 && $h < 16) $img = '/images/shows/DougStephan.png'; else if ($d == 3 && $h >= 16 && $h < 19) $img = '/images/shows/MariluHenner.png'; else if ($d == 3 && $h >= 19 && $h < 20) $img = '/images/shows/DebbieNigro.png'; else if ($d == 3 && $h >= 20 && $h < 22) $img = '/images/shows/DaveRamsey.png'; else if ($d == 3 && $h >= 22) $img = '/images/shows/JoyBrowne.png'; else if ($d == 4 && $h >= 0 && $h < 1) $img = '/images/shows/ShannonJoy.png'; else if ($d == 4 && $h >= 1 && $h < 2) $img = '/images/shows/BillNojay.png'; else if ($d == 4 && $h >= 2 && $h < 4) $img = '/images/shows/DennisPrager.png'; // THURSDAY SCHEDULE if ($d == 4 && $h >= 4 && $h < 5) $img = '/images/shows/DennisPrager.png'; else if ($d == 4 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 4 && $h >= 10 && $h < 13) $img = '/images/shows/BobRick.png'; else if ($d == 4 && $h >= 13 && $h < 16) $img = '/images/shows/DougStephan.png'; else if ($d == 4 && $h >= 16 && $h < 19) $img = '/images/shows/MariluHenner.png'; else if ($d == 4 && $h >= 19 && $h < 20) $img = '/images/shows/DebbieNigro.png'; else if ($d == 4 && $h >= 20 && $h < 22) $img = '/images/shows/DaveRamsey.png'; else if ($d == 4 && $h >= 22) $img = '/images/shows/JoyBrowne.png'; else if ($d == 5 && $h >= 0 && $h < 1) $img = '/images/shows/ShannonJoy.png'; else if ($d == 5 && $h >= 1 && $h < 2) $img = '/images/shows/BillNojay.png'; else if ($d == 5 && $h >= 2 && $h < 4) $img = '/images/shows/DennisPrager.png'; // FRIDAY SCHEDULE if ($d == 5 && $h >= 4 && $h < 5) $img = '/images/shows/DennisPrager.png'; else if ($d == 5 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 5 && $h >= 10 && $h < 13) $img = '/images/shows/BobRick.png'; else if ($d == 5 && $h >= 13 && $h < 16) $img = '/images/shows/DougStephan.png'; else if ($d == 5 && $h >= 16 && $h < 19) $img = '/images/shows/MariluHenner.png'; else if ($d == 5 && $h >= 19 && $h < 20) $img = '/images/shows/DebbieNigro.png'; else if ($d == 5 && $h >= 20 && $h < 22) $img = '/images/shows/DaveRamsey.png'; else if ($d == 5 && $h >= 22) $img = '/images/shows/JoyBrowne.png'; else if ($d == 6 && $h >= 0 && $h < 1) $img = '/images/shows/ShannonJoy.png'; else if ($d == 6 && $h >= 1 && $h < 2) $img = '/images/shows/BillNojay.png'; else if ($d == 6 && $h >= 2 && $h < 4) $img = '/images/shows/DennisPrager.png'; // SATURDAY SCHEDULE if ($d == 6 && $h >= 4 && $h < 5) $img = '/images/shows/DennisPrager.png'; else if ($d == 6 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 6 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 6 && $h >= 10 && $h < 12) $img = '/images/shows/HaidtReport.png'; else if ($d == 6 && $h >= 12 && $h < 13) $img = '/images/shows/ABCNews.png'; else if ($d == 6 && $h >= 13 && $h < 16) $img = '/images/shows/GarySullivan.png'; else if ($d == 6 && $h >= 16 && $h < 18) $img = '/images/shows/PopularTech.png'; else if ($d == 6 && $h >= 18 && $h < 19) $img = '/images/shows/WhatWorks.png'; else if ($d == 6 && $h >= 19 && $h < 21) $img = '/images/shows/JillMoney.png'; else if ($d == 6 && $h >= 21 && $h < 23) $img = '/images/shows/YouManual.png'; else if ($d == 6 && $h >= 23) $img = '/images/shows/MadeAmerica.png'; else if ($d == 0 && $h >= 0 && $h < 1) $img = '/images/shows/MensHealth.png'; else if ($d == 0 && $h >= 1 && $h < 2) $img = '/images/shows/AlanTaylor.png'; else if ($d == 0 && $h >= 2 && $h < 4) $img = '/images/shows/HughHewitt.png'; ?> <img src="<?php echo $img; ?>">Thank You! Kevin Please help! User enters Date (that is somewhere in future, few hours or maybe few years). I need to store in MYSQL Date minus 6 hours keeping in mind daylight savings time. I tried to convert date to unix timestamp and subtract 6*60*60. Works great, but does not take into consideration daylight savings time. Code: [Select] <?php if(date('w') == 0) $str = 'today'; else $str = 'last sunday'; $timestamp = strtotime($str); //echo $timestamp; echo "<img src='brn_masthead.gif' width='500' /><br /><table border='1'><tr>"; echo "<tr><td align='center' width='140'><b>Sunday</b></td><td align='center' width='140'><b>Monday</b></td><td align='center' width='140'><b>Tuesday</b></td><td align='center' width='140'><b>Wednesday</b></td> <td align='center' width='140'><b>Thursday</b></td><td align='center' width='140'><b>Friday</b></td><td align='center' width='140'><b>Saturday</b></td></tr><tr>"; $j = 0; for($i = 0; $i < 14; $i++) { $thisdate = date('Y-m-d', $timestamp + ($i * (60 * 60 * 24))); ?> I've looked into mktime and checked the manual, but can't find anything that seems to work inside the loop. Thanks! Here is the scenario: Members of my group turn in/donate uniform items they don't need to me...stuff that can be passed on to other members that need it. I post these items onto our website. A member, who needs an item, visits the site, and picks the items that they need. After selecting everything they need, they provide only their name and maybe some comments, and submit the request. An e-mail is generated and sent to me, listing out all the items the member has requested. I gather the items, and bring them to the member at the next meeting. My original plans were to use a shopping cart type script; however, I have since found out that I am not allowed a MySQL database on the server I am using! I've seen some shopping carts out there that use php & excel, not requiring a database, but they are all trial, and have limitations of only like 10 items. Does anyone have any ideas on the best way to handle this scenario? I was thinking an html form of some type with check boxes next to each item; then, upon pressing submit, a php script sends me an e-mail listing the boxes they have checked. Only problem with that is, having to update the php script each time I add/delete an item and it's checkbox (would have to add/delete that checkbox's name to the script each time...correct?). Thanks for any suggestions, - Jason Hey, I have a search feature that searches for words in my database. I am currently storing all searches that users make in a table called `search`. I need to list the top 10 words that are searched for the most, excluding common words like "the, and, or, etc". Because the searches users make are stored into a table, it should be fairly easy. Could anyone give an example of how to do this? Here's how my sql table looks: table name: search columns: id (autoincrement) phrase date resultsfound ip With this code I can determine the fieldname and the value. They are $col_key and $col_value respectively: Code: [Select] $sql = "SELECT * FROM $tbl "; $result = mysql_query($sql) while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($row == 1) { foreach ($line as $col_key => $col_value) { But how do I determine the field TYPE (i.e. varchar, text, date etc)? I have a PHP script that downloads a file from a remote server but in order to download the correct file it has to subtract 1 day of the week. It used to work quite some time ago so I dont know what is going on now. The section of the script goes like this....
$days = array("sun","mon","tue","wed","thu","fri","sat"); $today = date("w"); $yesterday = $days[$today - 1];Then it joins the 3 letter version of the day of week with a file name to grab the correct file download. $yesterday is not returning the correct value instead I am getting an error... # ./update.php PHP Notice: Undefined offset: -1 in /root/fcc/work/update.php on line 6 fetching l_am_.zip ncftpget: server said: l_am_.zip: No such file or directory. PHP Warning: unlink(counts): No such file or directory in /root/fcc/work/update.php on line 23 data set empty nothing to process Sun, 01 February, 2015 6:29:06 PMSo in the above error I can see that $yesterday is "Undefined offset" and because of that the file it tries to download is incorrect, it should have tried to download l_am_sat.zip and it left out the 3 letter date code. Edited by chadrt, 01 February 2015 - 09:48 PM. Hi Guys Quick question. I am just starting an application that enables users to upload files - specifically image files. As one of the validation/security steps I want to run a check on file type and file size. As far as i can see you do this one of two ways: 1) using the $_FILES array - i.e. $_FILES[name][type] and $_FILES[name][size] or 2) using the getimagesize() function. What i want to know is whether one of these methods is preferable for security or do they both suffer the same inherent flaws - because lots of post online seem to suggest filetype can be faked. advice would be appreciated Could someone please advise the best way to determine the average of a DATE field in a SELECT query?
When a user logs on, I authenticate them with a session. How do I use php to determine the time until the session will expire? I realize I could go into the ini file but is there a php code that can query this info and echo it back? Hi, I found a tutorial online for a form which used PHP/MySQL and JQuery to submit data. I am making some modifications and the form no-longer submits the data. The problem I have is no errors display so I am not sure where the problem lies. I need to be able to display a success or failure message on the form itself, but this is either not there or not working. The code is below. Code: [Select] <form id="ContactForm" action=""> <p> <label>First Name</label> <input id="FirstName" name="FirstName" class="inplaceError" maxlength="120" type="text" autocomplete="off"/> <span class="error" style="display:none;"></span> </p> <p> <label>Last Name</label> <input id="LastName" name="LastName" class="inplaceError" maxlength="120" type="text" autocomplete="off"/> <span class="error" style="display:none;"></span> </p> <p> <label>User Name</label> <input id="UserName" name="UserName" class="inplaceError" maxlength="120" type="text" autocomplete="off"/> <span class="error" style="display:none;"></span> </p> <p> <label>Email</label> <input id="email" name="email" class="inplaceError" maxlength="120" type="text" autocomplete="off"/> <span class="error" style="display:none;"></span> </p> <p> <label>Website<span>(optional)</span></label> <input id="website" name="website" class="inplaceError" maxlength="120" type="text" autocomplete="off"/> </p> <p> <label>Your message<br /> <span>300 characters allowed</span></label> <textarea id="message" name="message" class="inplaceError" cols="6" rows="5" autocomplete="off"></textarea> <span class="error" style="display:none;"></span> </p> <p class="submit"> <input id="send" type="button" value="Submit"/> <span id="loader" class="loader" style="display:none;"></span> <span id="success_message" class="success"></span> </p> <input id="newcontact" name="newcontact" type="hidden" value="1"></input> </form> <?php require_once("config.php"); /* Configuration File */ class DB{ private $link; public function __construct(){ $this->link = mysqli_connect(DB_SERVER, DB_USER, DB_PASS,DB_NAME); if (mysqli_connect_errno()) exit(); } public function __destruct() { mysqli_close($this->link); } public function dbNewMessage($email,$FirstName,$LastName,$website,$message){ $email = mysqli_real_escape_string($this->link,$email); $FirstName = mysqli_real_escape_string($this->link,$FirstName); $LastName = mysqli_real_escape_string($this->link,$LastName); $UserName = mysqli_real_escape_string($this->link,$UserName); $website = mysqli_real_escape_string($this->link,$website); $message = mysqli_real_escape_string($this->link,$message); mysqli_autocommit($this->link,FALSE); $query = "INSERT INTO contact_me(pk_contact,FirstName,LastName,UserName,email,website,message) VALUES('NULL','$FirstName','$LastName','$UserName','$email','$website','$message')"; mysqli_query($this->link,$query); if(mysqli_errno($this->link)) return -1; else{ mysqli_commit($this->link); return 1; } } }; ?> <?php require_once("db.php"); /* Database Class */ require_once('utils/is_email.php'); /* Email Validation Script */ /* Handle Ajax Request */ if(isset($_POST['newcontact'])){ $contact = new Contact(); unset($contact); } else{ header('Location: /'); } /* Class Contact */ class Contact{ private $db; /* the database obj */ private $errors = array(); /* holds error messages */ private $num_errors; /* number of errors in submitted form */ public function __construct(){ $this->db = new DB(); if(isset($_POST['newcontact'])) $this->processNewMessage(); else header("Location: /"); } public function processNewMessage(){ $email = $_POST['email']; $FirstName = $_POST['FirstName']; $LastName = $_POST['LastName']; $UserName = $_POST['UserName']; $website = $_POST['website']; $message = $_POST['message']; /* Server Side Data Validation */ /* Email Validation */ if(!$email || mb_strlen($email = trim($email)) == 0) $this->setError('email','required field'); else{ if(!is_email($email)) $this->setError('email', 'invalid email'); else if(mb_strlen($email) > 120) $this->setError('email', 'too long! 120'); } /* FirstName Validation */ if(!$FirstName || mb_strlen($FirstName = trim($FirstName)) == 0) $this->setError('FirstName', 'required field'); else if(mb_strlen(trim($FirstName)) > 120) $this->setError('FirstName', 'too long! 120 characters'); /* LastName Validation */ if(!$LastName || mb_strlen($LastName = trim($LastName)) == 0) $this->setError('LastName', 'required field'); else if(mb_strlen(trim($LastName)) > 120) $this->setError('LastName', 'too long! 120 characters'); /* UserName Validation */ if(!$UserName || mb_strlen($UserName = trim($UserName)) == 0) $this->setError('UserName', 'required field'); else if(mb_strlen(trim($UserName)) > 120) $this->setError('UserName', 'too long! 120 characters'); /* Website Validation */ if(!mb_eregi("^[a-zA-Z0-9-#_.+!*'(),/&:;=?@]*$", $website)) $this->setError('website', 'invalid website'); elseif(mb_strlen(trim($website)) > 120) $this->setError('website', 'too long! 120 characters'); /* Message Validation */ $message = trim($message); if(!$message || mb_strlen($message = trim($message)) == 0) $this->setError('message','required field'); elseif(mb_strlen($message) > 300) $this->setError('message', 'too long! 300 characters'); /* Errors exist */ if($this->countErrors() > 0){ $json = array( 'result' => -1, 'errors' => array( array('name' => 'email' ,'value' => $this->error_value('email')), array('name' => 'FirstName' ,'value' => $this->error_value('FirstName')), array('name' => 'LastName' ,'value' => $this->error_value('LastName')), array('name' => 'UserName' ,'value' => $this->error_value('UserName')), array('name' => 'website' ,'value' => $this->error_value('website')), array('name' => 'message' ,'value' => $this->error_value('message')) ) ); $encoded = json_encode($json); echo $encoded; unset($encoded); } /* No errors, insert in db*/ else{ if(($ret = $this->db->dbNewMessage($email, $FirstName, $LastName,$UserName, $website, $message)) > 0){ $json = array('result' => 1); if(SEND_EMAIL) $this->sendEmail($email,$name,$website,$message); } else $json = array('result' => -2); /* something went wrong in database insertion */ $encoded = json_encode($json); echo $encoded; unset($encoded); } } public function sendEmail($email,$name,$website,$message){ /* Just format the email text the way you want ... */ $message_body = "Hi, ".$name."(".$email." - ".$website.") sent you a message from yoursite.com\n" ."email: ".$email."\n" ."message: "."\n" .$message; $headers = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">"; return mail(EMAIL_TO,MESSAGE_SUBJECT,$message_body,$headers); } public function setError($field, $errmsg){ $this->errors[$field] = $errmsg; $this->num_errors = count($this->errors); } public function error_value($field){ if(array_key_exists($field,$this->errors)) return $this->errors[$field]; else return ''; } public function countErrors(){ return $this->num_errors; } }; ?> and the JQuery Code: [Select] $(document).ready(function() { contact.initEventHandlers(); }); var contact = { initEventHandlers : function() { /* clicking the submit form */ $('#send').bind('click',function(event){ $('#loader').show(); setTimeout('contact.ContactFormSubmit()',500); }); /* remove messages when user wants to correct (focus on the input) */ $('.inplaceError',$('#ContactForm')).bind('focus',function(){ var $this = $(this); var $error_elem = $this.next(); if($error_elem.length) $error_elem.fadeOut(function(){$(this).empty()}); $('#success_message').empty(); }); /* user presses enter - submits form */ $('#ContactForm input,#ContactForm textarea').keypress(function (e) { if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) { $("#send").click(); return false; } else return true; }); }, ContactFormSubmit : function() { $.ajax({ type : 'POST', url : 'php/contact.php?ts='+new Date().getTime(), dataType : 'json', data : $('#ContactForm').serialize(), success : function(data,textStatus){ //hide the ajax loader $('#loader').hide(); if(data.result == '1'){ //show success message $('#success_message').empty().html('Message sent'); //reset all form fields $('#ContactForm')[0].reset(); //envelope animation $('#envelope').stop().show().animate({'marginTop':'-175px','marginLeft':'-246px','width':'492px','height':'350px','opacity':'0'},function(){ $(this).css({'width':'246px','height':'175px','margin-left':'-123px','margin-top':'-88px','opacity':'1','display':'none'}); }); } else if(data.result == '-1'){ for(var i=0; i < data.errors.length; ++i ){ if(data.errors[i].value!='') $("#"+data.errors[i].name).next().html('<span>'+data.errors[i].value+'</span>').fadeIn(); } } }, error : function(data,textStatus){} }); } }; I am trying to write a script that runs through a CSV file and inserts unique values in a mysql database and spits the duplicate out into a new CSV. I can find the duplicates when I load it into an array, but when I insert them into a MySQL database, I cannot determine if they are duplicates. If I use INSERT IGNORE, it will run the whole file, and reject the duplicates. This is fine, except I need to create a file of the duplicate entries. What is the best way to determine if the insert attempt was rejected? I could do a select to see if the row is there, spit it out...insert if not, but I was thinking there should be a way for MySQL to talk back to me to cut the queries in half... Any ideas? Thanks 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 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."; } Basically I have recently been playing around with parsing a csv file. What I am looking to do at this point is simply take the date/timestamp (part of the csv file), which is in the following format:DD/MM HH:MM:SS.100th/s For the sake of argument, lets say I have this in an array string called $csv[0] and the file has several lines that span the course of a couple hours. I wouldn't mind having to use explode() to breakup/remove the date or 100th/s IF that would make things a lot simpler. So where would I start in trying to achieve this?. The result I am looking for will simply return "X Seconds". Storing this in a string variable would be a bonus, as I plan to use this to divide a separate piece of information. Any examples or ideas would be great. Thank you. ps: Here is an example time from the csv file itself: Code: [Select] 11/19 22:23:18.143 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. This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=316461.0 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!
What are the differences and implications of UTC time and Zulu time? <?php function getArr(string $time):array { $dateTime = new \DateTime($time); return [ 'time'=>$time, 'timestamp'=> $dateTime->getTimestamp(), 'dateTime' => $dateTime ]; } $arr = getArr('2020-08-05'); $arr_z = getArr('2020-08-05T00:00:00Z'); print_r($arr); print_r($arr_z); echo('equal timestamps: '.($arr['timestamp'] === $arr['timestamp']?'true':'false'));
Array ( [time] => 2020-08-05 [timestamp] => 1596585600 [dateTime] => DateTime Object ( [date] => 2020-08-05 00:00:00.000000 [timezone_type] => 3 [timezone] => UTC ) ) Array ( [time] => 2020-08-05T00:00:00Z [timestamp] => 1596585600 [dateTime] => DateTime Object ( [date] => 2020-08-05 00:00:00.000000 [timezone_type] => 2 [timezone] => Z ) ) equal timestamps: true
|