Date Addition and Subtraction

By Hawkee on Nov 02, 2005

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.

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

Sign in to comment.
F*U*R*B*Y*   -  Mar 15, 2006

oh okay so then i just need to echo $date

 Respond  
Hawkee   -  Mar 14, 2006

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.

 Respond  
F*U*R*B*Y*   -  Mar 10, 2006

this doesn\'t work for me :$

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.