<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nir Gofman</title>
    <description>The latest articles on DEV Community by Nir Gofman (@gofmannir).</description>
    <link>https://dev.to/gofmannir</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F250031%2Fa6a14a2e-5b01-4dc0-9f2a-b9be488c781d.png</url>
      <title>DEV Community: Nir Gofman</title>
      <link>https://dev.to/gofmannir</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gofmannir"/>
    <language>en</language>
    <item>
      <title>That's how I came back in time</title>
      <dc:creator>Nir Gofman</dc:creator>
      <pubDate>Wed, 16 Oct 2019 18:09:07 +0000</pubDate>
      <link>https://dev.to/gofmannir/that-s-how-i-came-back-in-time-41nc</link>
      <guid>https://dev.to/gofmannir/that-s-how-i-came-back-in-time-41nc</guid>
      <description>&lt;p&gt;Few days ago one of my clients asked for a little php script that will add the date when users opens a new ticket in his website's tickets system where they can contact the website administrators..&lt;/p&gt;

&lt;p&gt;It's pretty simple right?, all it requires is to add a new column in the 'Tickets' MySQL table (I love to define this column as tinytext and not as date field).&lt;br&gt;
And, in the $_POST form operation - get the date with the php date() function, add or reduce hours or minutes depends on the server time.&lt;/p&gt;

&lt;p&gt;Surprisingly, in the DB I saw the date 1/1/1970 1:00 for every form entry. What The H....&lt;br&gt;
So I started exploring.&lt;br&gt;
This is how I get the date:&lt;/p&gt;

&lt;pre&gt;
$newdate = date("d/m/Y H:i");
$newdate = strtotime('+1 hour', strtotime ($newdate));
$newdate = date ( 'd/m/Y H:i' , $newdate );
echo $newdate;
&lt;/pre&gt;

&lt;p&gt;it outputs 1/1/1970 2:00, if I delete the second and the third lines (which adds an hour) the output is the actual date and time. WHY?&lt;/p&gt;

&lt;h2&gt;
  
  
  Steps for debugging this issue:
&lt;/h2&gt;

&lt;h4&gt;
  
  
  1. Enabling error display and error reporting in the php file:
&lt;/h4&gt;

&lt;pre&gt;
ini_set('display_errors', 1);
error_reporting(E_ALL);
&lt;/pre&gt;

&lt;p&gt;One's we enabled that we can't see &lt;em&gt;ANY&lt;/em&gt; errors. Seems like everything is O.K. &lt;/p&gt;

&lt;h4&gt;
  
  
  2. Exploring the strtotime() function in the menual:
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Description:&lt;/em&gt;&lt;br&gt;
&lt;em&gt;strtotime ( string $time [, int $now = time() ] ) : int&lt;/em&gt;&lt;br&gt;
"The function expects to be given a string containing an English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC), &lt;strong&gt;relative to the timestamp given in now&lt;/strong&gt;, or the current time if now is not supplied."&lt;/p&gt;

&lt;p&gt;I was given 'now' when I wanted to add 1 hour. Which means the format I'm trying to pass is not valid.&lt;br&gt;
After more research I needed to replace the Slashes ( / ) with Hyphen ( - ) And the edit looks like this:&lt;/p&gt;

&lt;pre&gt;
$newdate = date("d-m-Y H:i");
$newdate = strtotime ( '+1 hour' , strtotime ( $newdate ) ) ;
$newdate = date ( 'd/m/Y H:i' , $newdate );
echo $newdate;
&lt;/pre&gt;

&lt;p&gt;That's it!&lt;br&gt;
These slashes made the date to be in invalid format which strtotime() function can't handle.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Next time, I will read the formats valid for all the php functions, I didn't expected that this / so different from this - .
&lt;/h3&gt;

&lt;p&gt;Thank you for reading,&lt;br&gt;
Nir. &lt;/p&gt;

</description>
      <category>php</category>
      <category>sql</category>
    </item>
  </channel>
</rss>
