PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
tdelobe
Forum Commoner
Posts: 41 Joined: Thu Aug 07, 2003 2:28 pm
Location: washington, dc
Post
by tdelobe » Sun Dec 26, 2004 8:32 pm
I can not figure out how to return a date in the form of 2004/12/26 but have it return today's date minus 1 month. I have this, but I am on windows and it can not take a negative number.
Code: Select all
$lastmonth = date("Y") . "/" . date("m")-1 . "/" . date("d");
So, on unix that would work, but not on windows. How can I get this to work?
Joe
Forum Regular
Posts: 939 Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow
Post
by Joe » Sun Dec 26, 2004 8:37 pm
Try:
Code: Select all
<?php
$year = date("Y");
$month = date("m");
$day = date("d");
$month_math = $month - 1;
$lastmonth = $year . "/" . $month_math . "/" . $day;
?>
njwan
Forum Newbie
Posts: 8 Joined: Wed Jul 28, 2004 1:52 am
Post
by njwan » Sun Dec 26, 2004 8:57 pm
Code: Select all
$lastmonth = date("Y") . "/" .(date("m")-1). "/" . date("d");
Robert Plank
Forum Contributor
Posts: 110 Joined: Sun Dec 26, 2004 9:04 pm
Contact:
Post
by Robert Plank » Sun Dec 26, 2004 9:05 pm
Those ways will still show 0 for the month if it is January. Do it this way:
Code: Select all
$lastmonth = date("Y\/m\/d", strtotime("-1 month"));
tdelobe
Forum Commoner
Posts: 41 Joined: Thu Aug 07, 2003 2:28 pm
Location: washington, dc
Post
by tdelobe » Sun Dec 26, 2004 9:17 pm
Thanks!! This one worked.....fiiiiiiiiiiiinally!
Code: Select all
$lastmonth = date("Y\/m\/d", strtotime("-1 month"));