Veronica's Time & Date Detailer

This form provides details of a date based on input

String:


Enter a string like the examples below. That string will be evaluated via the strtotime() and getdate() functions.

For example, try entering strings like:
"tomorrow 5:35pm"
"Today"
"yesterday"
"Next Year"
"+12 weeks Wednesday"
"-52 Sundays"
"January 1, 2003"

Abe Lincoln
Close up photo of a 5 dollar bill by Veronica Hutchins, Nov. 2024

You can try your birthday, too. Abraham Lincoln was born on February 12, 1809. Use this form to see what day of the week that was.

 

CODE FOLLOWS

<?php

include('includes/header.php');

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

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

// variables
$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> Veronica's Time & Date Detailer</h1>

    <h2>This form provides details of a date based on input</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 like the examples below. That string will be evaluated via the
        strtotime() and getdate() functions.
    </p>

    <p>
        For example, try entering strings like:<br>"tomorrow 5:35pm"<br>"Today"
        <br>"yesterday"<br>"Next Year"<br>"+12 weeks Wednesday"
        <br>"-52 Sundays"<br>"January 1, 2003"
    </p>

    <div id="picture">
        <img src="../images/abe_lincoln_5dollarbill_sm.jpg" class="floatR" alt="Abe Lincoln"><br>
        Close up photo of a 5 dollar bill by Veronica Hutchins, Nov. 2024
    </div>

    <p>
        You can try your birthday, too. Abraham Lincoln was born on February 12, 1809. Use this
        form to see what day of the week that was.
    </p>

    <?php
}
else
{
    
// change string into seconds
    
$seconds strtotime($string);
    
// change seconds into a date
    
$date getdate($seconds);
    
$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> Veronica's Time Demonstration - Part 2</h1>

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

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

    <p>
        The day of the week = <?php echo($date['weekday']); ?>.
    </p>

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

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

    <p>
        The month had / will have: <?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
}
// close of else statement

include('includes/footer.php');

?>