Top

Date Addition and Subtraction


PHP Code
+ 0 likes
Please Register to submit score.
Bookmark and Share
Average Score  7.0 (of 1 scores)
Date Added  Nov 02, 2005
Last Updated  Nov 02, 2005
Tags  date  time  timestamp 

Description

I thought this was pretty neat and useful. You can combine strtotime with the date function to create your own date verbally. This is just an alternative to using mktime that's a little more intuitive.

Grab the Code

<?php
 
$date = date('Y-m-d', strtotime("-30 days"));
$date = date('Y-m-d', strtotime("-10 years"));
$date = date('Y-m-d', strtotime("+30 days"));
 
?>

Comments

  (3)  RSS
F*U*R*B*Y*
Comments: 627
 
PHP Snippet:  Date Addition and Subtraction
Posted on Mar 10, 2006 8:51 pm
this doesn't work for me :$
Hawkee
Comments: 1,092
 
PHP Snippet:  Date Addition and Subtraction
Posted on Mar 14, 2006 7:07 pm
All it does is set the $date variable to a time specified by strtotime. It's a nice example of how convenient PHP makes dealing with time and dates.
F*U*R*B*Y*
Comments: 627
 
PHP Snippet:  Date Addition and Subtraction
Posted on Mar 15, 2006 2:31 am
oh okay so then i just need to echo $date

Commenting Options

Register or Login to Hawkee.com or use your Facebook or Twitter account by clicking the corresponding button below.

  

Bottom