Tedd's "String To Time" DEMO

String:


Enter a string and that string will be evaluated through the strtotime() function.

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

 

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>Tedd's "String To Time" DEMO</h1>

            <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 through the strtotime() function.
            </p>

            <p>
                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>

            <?php
        
}
    else
        {

        
$seconds strtotime($string);    // change string to seconds
        
$date getdate($seconds);        // change seconds to a date
        
$computedDate $date['mday'] . ' ' $date['month'] . ', ' $date['year'] . ' : ' $date['weekday'];
        
?>

            <pre>
            <?php
                print_r
($date);
            
?>
        </pre>

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

            <p>
                Seconds computed from String: <?php echo($seconds); ?>
            </p>

            <p>
                Seconds taken To Date: <?php echo($computedDate); ?>
            </p>

            <p>
                Current Time (seconds): <?php echo(time()); ?>
            </p>

            <p>
                Current Date: <?php echo(date("d F, Y : l")); ?>
            </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
        
}        // end brace of above else

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