<!doctype html>
<?php
  date_default_timezone_set("America/New_York");
?>
<html>
  <head>
    <title>Using the strtotime() function</title>
    <link href="https://jimgerland.com/includes/css/styles.css" rel="stylesheet" />
    <link href="https://jimgerland.com/includes/css/codestyles.css" rel="stylesheet" />
  </head>
  <body>
    <div style="font-family: Courier, Arial, Sans-Serif; font-size2 large;">
      <h2>How to generate a timestamp with an absolute template</h1>
      <code>
      // Examples assume a current time of <?php echo(date('l, m/d/Y h:m') . "<br />"); ?>
      $date1 = strtotime('2020-09-11');
      <?php $date1 = strtotime('2020-09-11'); echo("// $date1 " . date('m/d/Y', $date1) . "<br />"); ?>
      $date2 = strtotime('9/11/2020');
      <?php $date2 = strtotime('9/11/2020'); echo("// $date2 " . date('m/d/Y', $date2) . "<br />"); ?>
      $date3 = strtotime('Sep 11');
      <?php $date3 = strtotime('Sep 11'); echo("// $date3 " . date('m/d/Y', $date3) . "<br />"); ?>
      $date4 = strtotime('8:45 am'); 
      <?php $date4 = strtotime('8:45 am'); echo("// $date4 " . date('h:m a', $date4) . "<br />"); ?>
      $date5 = strtotime('8am');
      <?php $date5 = strtotime('8am'); echo("// $date5 " . date('h a', $date5) . "<br />"); ?>
      $date6 = strtotime('2020-09-11 8:45 am');
      <?php $date6 = strtotime('2020-09-11 8:45 am'); echo("// $date6 " . date('m/d/Y h:m a', $date6) . "<br />"); ?>
      </code>          
      <h2>How to generate a timestamp with a relative template</h2>
      <code>
      // Examples assume a current time of <?php echo(date('l, m/d/Y h:m') . "<br />"); ?>
      $date1 = strtotime('+1 hour');
      <?php $date1 = strtotime('+1 hour'); echo("// " . date('h:i a', $date1) . "<br />"); ?> 
      $date2 = strtotime('-2 days'); 
      <?php $date2 = strtotime('-2 days'); echo("// " . date('m/d/Y', $date2) . "<br />"); ?> 
      $date3 = strtotime('tomorrow');
      <?php $date3 = strtotime('tomorrow'); echo("// " . date('m/d/Y', $date3) . "<br />"); ?> 
      $date4 = strtotime('tomorrow 10:15am');
      <?php $date4 = strtotime('tomorrow 10:15am'); echo("// " . date('m/d/Y h:i a' ,$date4) . "<br />"); ?> 
      $date5 = strtotime('next sunday');
      <?php $date5 = strtotime('next sunday'); echo("// " . date('m/d/Y', $date5) . "<br />"); ?> 
      $date6 = strtotime('last day of');
      <?php $date6 = strtotime('last day of'); echo("// " . date('m/d/Y', $date6) . "<br />"); ?> 
      $date7 = sttotime('first day of next month');
      <?php $date7 = strtotime('first day of next month'); echo("// " . date('m/d/Y', $date7) . "<br />"); ?> 
      $date8 = strtotime('third wednesday of');
      <?php $date8 = strtotime('third wednesday of'); echo("// " . date('m/d/Y', $date8) . "<br />"); ?> 
      $date9 = strtotime('nov second thu of 8am');
      <?php $date9 = strtotime('nov second thu of 8am'); echo("// " . date('m/d/Y h:i a', $date9) . "<br />"); ?> 
      </code>
      <h2>How to modify a timestamp</h2>
      <code>
      $checkout = mktime(13, 30, 0, 9, 8, 2017);
      <?php $checkout = strtotime('+1 hour'); echo("// $checkout " . date('m/d/Y h:m a', $checkout) . "<br />"); ?>
      $due_date = strtotime('+3 weeks 6pm', $checkout);
      <?php $due_date = strtotime('+3 weeks 6pm'); echo("// $due_date " . date('m/d/Y h:m a', $due_date) . "<br />"); ?>
      </code>
      <ul>
        <li>An absolute template specifies a specific date, time, or both.</li>
        <li>A relative template specifies an offset to the base date and time. To specify an offset, you can use most English descriptions of time and date offsets</li>
      </ul>
    </div>
    <p><a href=".">Back</a></p>
  </body>
</html> 