a better date calculation in php?

Waubain

New Member
I am a teacher that uses HTML to provide simulations for my students. The simulations have a chronological date time line. Every time I want to use the simulation I have to go in and change all the dates to keep the realistic time line. I started reading about php and what to change the dates dynamically. My simulations on on a local server and do not go outside my class room.

Since dates appear many times in my simulations on many different pages, I am looking for code that works in with the fewest lines of code. The code will almost always be in a table cell.

This simple example works for yesterday's date.

Code:
<body>
<?php
    date_default_timezone_set("America/Chicago");
    $today = time();
    $day = 86400 ;
?>

<table>
    <tr>
	   <td><?php 
                    $newdate = $today - ($day *1); 
                    echo date("m/d/y", $newdate);
                   ?>
           </td>
    </tr>
</table>

</body>

Thank you for any suggestions....Waubain
 

conor

New Member
to get the current date you could use something like this:

Code:
<body>
<?php
    date_default_timezone_set("America/Chicago");
?>
<table>
    <tr>
	   <td><?php 
                    echo date( "m/d/y" );
                   ?>
           </td>
    </tr>
</table>

</body>
 

MarkR

New Member
If your function is to appear in many different files I would have one php file called date_inc.php and put your date code in it something like:

PHP:
    date_default_timezone_set("America/Chicago");
    $today = time();
    $day = 86400 ;

    $newdate = $today - ($day *1); 
    echo date("m/d/y", $newdate);

Then in all your other files you can just use:

PHP:
require_once('date_inc.php');

That way you only have to change one file to make a global date change.
 
Top