Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, you need to understand the difference between the <a href="http://www.php.net/manual/en/function.date.php" rel="noreferrer"><code>date()</code></a>, <a href="http://www.php.net/manual/en/function.time.php" rel="noreferrer"><code>time()</code></a>, and <a href="http://www.php.net/manual/en/function.mktime.php" rel="noreferrer"><code>mktime()</code></a>.</p> <p><a href="http://www.php.net/manual/en/function.date.php" rel="noreferrer"><code>date()</code></a> is used for display purposes only. Never use it for mathematical manipulations.</p> <p><a href="http://www.php.net/manual/en/function.time.php" rel="noreferrer"><code>time()</code></a> returns the current <code>timestamp</code> (an <code>int</code> representing the current time and date).</p> <p><a href="http://www.php.net/manual/en/function.mktime.php" rel="noreferrer"><code>mktime()</code></a>, without any parameters, is the same as <a href="http://www.php.net/manual/en/function.time.php" rel="noreferrer"><code>time()</code></a>. With parameters, it allows you to get a <code>timestamp</code> for a set time. The parameters are in this order: Hour, Minute, Second, Month, Day, Year.</p> <p>Now, <strong>your questions</strong>:</p> <h2>Question 1</h2> <p>To do time manipulation, you can do the following:</p> <pre><code>$today = mktime(0,0,0); //Today, time neutral $otherDate = mktime(0, 0, 0, 6, 26, 2008); //2008-06-26, time neutral $secondsBetweenDates = $today - $otherDate; </code></pre> <h2>Question 2</h2> <p>You are better of doing something like that directly in your SQL. Here are ways you can do it for the two most common database servers running in PHP. I'm assuming <code>DateSubscribed</code> is in a valid date datatype.</p> <pre><code>--- MySQL DELETE FROM `subscribers` WHERE NOW() &lt; DATE_ADD(`DateSubscribed`, INTERVAL 1 WEEKS); --- PostgreSQL DELETE FROM "subscribers" WHERE CURRENT_TIMESTAMP &lt; ("DateSubscribed" + interval '1 week'); </code></pre> <h2>Question 3</h2> <p>That depends on your DBMS. Here are the documentation pages related to Date/Time Functions for both MySQL and PostgreSQL</p> <ul> <li>MySQL: <a href="http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html" rel="noreferrer">11.6. Date and Time Functions</a></li> <li>PostgreSQL: <a href="http://www.postgresql.org/docs/8.3/interactive/functions-datetime.html" rel="noreferrer">9.9. Date/Time Functions and Operators</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload