Web Design Forum  
 
Go Back   Web Design Forum > Web Software > Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-04-2012, 03:24 PM   #1
New Member
 
Join Date: May 2011
Posts: 4
Default a better date calculation in php?

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
Waubain is offline   Reply With Quote


Old 03-05-2012, 10:37 PM   #2
Gold Member
 
conor's Avatar
 
Join Date: Oct 2008
Location: Ireland
Posts: 349
Default

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>
__________________
Conor
conor is offline   Reply With Quote
Old 03-06-2012, 08:54 AM   #3
Silver Member
 
Join Date: Aug 2011
Posts: 100
Default

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 Code:



    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 Code:
require_once('date_inc.php'); 
That way you only have to change one file to make a global date change.
__________________
Mark R

Wubbleyou - Web Design Newcastle
A professional web design agency based in Newcastle upon Tyne servicing clients based throughout the U.K.

Home spray tan machine - Landlord Reviews
MarkR is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 07:14 PM.


Camera Forum - Computer Forum - Web Design Forum

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.