Next entry >>
10.
27.
06
PHP Date Fun!
Categories: Internet , Genpets , Programming
Ambient: Deep Dish

While updating the genpets.com site I decided I wanted to add a forum, of course, not a real one as I don't have enough free time to police it. So I needed to create and code something that would look real, which means it would have to update all by itself.

The first trick to that was date control, if all the dates are set for this week, that's not going to do me much good a year from now is it?

I started out writing some longer if statments but then as I read more about the date commands in PHP I realized it could subtract the dates (or add) all on it's own, without having to be told HOW. (IE september 3rd minus 5 days, we'd have to tell the system to update the month to august)

Here's a little snippet of code I used, it works great, so feel free to cut and paste.

// this simple code controls how the dates work on the page. it subtracts days to make it appear the site is always being updated.
//it is also 'smart' so if it subtracts say 5 days from october 2, it will make it september... cool eh?

$date = date('m/d/Y', strtotime("-0 days"));
$date3 = date('m/d/Y', strtotime("-3 days"));

$date10 = date('m/d/Y', strtotime("-10 days"));

$date1 = date('m/d/Y', strtotime("-1 days"));

you don't have to subtract days either, you could subtract a month or year, or whatever suits your fancy, yes it will compensate for leap year etc...

 
| Newest comments last| Back

Emily said:
Hi Adam, it's Emily :D Cool bit of code you got there.

Posted on Saturday November 18, 2006 @ 07:08 am

Add a Comment

Comments must first be APPROVED before they are publicly viewable.
*Name:
Email:
(Hidden)
url:
*Comments:
  Remember my details
*Verify:
 
Please type the verification string for security purposes.
(* Required).
Line breaks and paragraphs are automatically converted
All HTML tags will be removed.
Comment Preview
says:

Posted on Tuesday February 07, 2012 @ 06:35pm


Page 1 of 1