Don Alexander Eckford's Time Date Demo

The following are examples of getdate() AND strtotime()

String:


Enter a string and that string will be evaluated via the getdate() and strtotime() functions.

For example, try strings like "tomorrow 1:30pm", or "Today", or "Yesterday", or "Next Month", or "+2 weeks monday", or "+2 mondays" and see what happens.

Angela Davis

Also try your birthday, like Angela Davis was born on January 26, 1944. What day of the week was that?

 

CODE FOLLOWS

<?php
    
include('includes/header.php');

    
// set timezone
    
date_default_timezone_set("America/Detroit");

    
error_reporting(E_ALL);    // set error reporting to all

    
$self basename($_SERVER['SCRIPT_NAME']);

    
$step = isset($_POST['step']) ? $_POST['step'] : 0;

    
// clean input from user
    
$string = isset($_POST['string']) ? $_POST['string'] : null;
    
$string htmlentities($string);

    if (
$step == 0)
    {
        
?>

        <h1> Don Alexander Eckford's Time Date Demo</h1>

        <h2>The following are examples of getdate() AND strtotime()</h2>

        <form action="<?php echo($self); ?>" method="POST">
            <fieldset>
                <legend>String:</legend>
                <label for="string">Time String: </label>
                <input type="text" size="36" id="string" name="string" value="">
            </fieldset>

            <p>
                <input type="hidden" name="step" value="1"> <br>
                <input type="submit" name="submit" value="Submit">
            </p>
        </form>

        <p>
            Enter a string and that string will be evaluated via the getdate()
            and strtotime() functions.
        </p>

        <p>
            For example, try strings like "tomorrow 1:30pm", or "Today",
            or "Yesterday", or "Next Month", or "+2 weeks monday",
            or "+2 mondays" and see what happens.
        </p>

        <img src="../images/Angela_Davis_en_Bogota_Septiembre_de_2010.jpg" class="floatR" alt="Angela Davis">

        <p>
            Also try your birthday, like Angela Davis  was born on January 26, 1944. What day of the week was that?
        </p>

        <?php
    
}
    else
    {
        
$seconds strtotime($string);    // change string into seconds
        
$date getdate($seconds);        // change seconds into a date
        
$computedDate $date['mday'] . ' ' $date['month'] . ', ' $date['year'];

        echo(
'<pre>');
        
print_r($date);
        echo(
'</pre>');


        
$str '';
        
$sec 0;

        if (
$seconds 0)
        {
            
$sec abs($seconds);
            
$str "Seconds from $computedDate to January 1, 1970 = $sec seconds.";
        }
        else
        {
            
$str "Seconds from January 1, 1970 to $computedDate = $seconds seconds.";
        }

        
?>

        <h1> Don Alexander Eckford's time (part 2)</h1>

        <p>
            String Provided: <?php echo($string); ?>
        </p>

        <p>
            Computed Date: <?php echo($computedDate); ?>
        </p>

        <p>
            It was a <?php echo($date['weekday']); ?>.
        </p>

        <p>
            The year was <?php echo($date['year']); ?>.
        </p>

        <p>
            The month was <?php echo($date['month']); ?>.
        </p>

        <p>
            The month had <?php echo(idate('t'$seconds)); ?> days.
        </p>

        <p>
            <?php echo($str); ?>
        </p>

        <p>
            Current Date = <?php echo(date("d F, Y : l")); ?>
        </p>

        <p>
            Current Time = <?php echo(time()); ?> seconds since January 1, 1970.
        </p>

        <form action="<?php echo($self); ?>" method="POST">
            <p>
                <input type="hidden" name="step" value="0">
                <input type="submit" name="submit" value="Try Again">
            </p>
        </form>

        <?php
    
}    // NOTE: closing brace for above else


    
include('includes/footer.php');
?>