traq;11021303 wrote:what weedpacket is implying (and he's correct) is that I made a typo. The name of the class is [man]DateInterval[/man].
I am so near-sited, both mentally and visually, that I didn't make the connection
As for how to set the value in a variable, you'd do it just like normal:
$x = $date->format( 'Y-m-d' );
$x would hold the string "2012-08-04", of course, not the date object itself. I don't know if that's what you wanted or not.
for your loop, you don't need to increment the interval, since [man]datetime.sub[/man] changes the date in $date. e.g.,
$date = new DateTime( '2012-08-04' );
$oneday = new DateInterval( 'P1D' );
print $date->sub( $oneday )->format( 'Y-m-d' ); // prints "2012-08-03"
print $date->sub( $oneday )->format( 'Y-m-d' ); // prints "2012-08-02"
// . . . etc.
I do need the counter because I'm not only figuring the date, I'm constructing an array with the counter, too. Also, it condenses 8 lines of code down to 4.
Here's what I blundered into:
for ($counter=0; $counter <= 6; $counter++)
{
$date = date_create($EndDate);
date_sub($date, date_interval_create_from_date_string($counter . 'days'));
$IncDate = date_format($date, 'Y-m-d');
$Quest = "SELECT * FROM `$System` WHERE TechNum = '$TechNum' && WorkDate = '$IncDate'";
$result = mysql_query($Quest, $cxn)
or die ('the bear went over the mountain ' . mysql_error());
..more code..
..more code...
}
Doing this eliminated 18 lines of code:
for ($counter=0; $counter <= 6; $counter++)
{
$date = date_create($EndDate);
date_sub($date, date_interval_create_from_date_string($counter . 'days'));
$W["$counter"] = date_format($date, "D");
$D["$counter"] = date_format($date, "n-j");
echo $counter . ' ** ' . $W["$counter"] . ' ## ' . $D["$counter"] . '<br>';
}
..more code..more code
for ($counter=0; $counter<=6; $counter++)
{
echo '<th style = "width:40px">' . $W["$counter"] . '<br>' . $D["$counter"] . '</th>';
}
Thanks very much for the hints. They pointed me where I needed to go.