[TriLUG] Perplexed
Brian Henning
brian at strutmasters.com
Tue Apr 4 11:27:59 EDT 2006
Er, not to be a pedant, but why aren't you using PHP's built-in
date/time functions?
check out date() and strtotime() to do what your shell commands
currently do. For example, here're a few lines from code I've written:
$now = strtotime("tomorrow");
$end = strtotime("Last Wednesday", $now); // Today's last Wednesday
$thismonth = strtotime(date("m/01/Y"));
for($m = 0; $m < 12; $m++) {
$s = ($m > 0) ? "s" : "";
$t_month[(11 - $m)] = strtotime(date("m/d/Y", $thismonth) . " -$m
month$s");
$n_month[(11 - $m)] = date("M", $t_month[(11 - $m)]);
}
strtotime is pretty good at understanding English descriptions of
moments in time, and date() can take a ton of arguments to format a
date/time stamp.
PHP manual for date():
http://us2.php.net/manual/en/function.date.php
for strtotime():
http://us2.php.net/manual/en/function.strtotime.php
HTH,
~Brian
Matt Frye wrote:
> Can someone tell me why the following code would not set $startdated
> to the correct date? Stuff inside the 'switch' seems to go into a
> black hole, even when it evals correctly.
>
> <?php
>
> $day = `date +%A`;
>
> print "<br>Day is $day - Before<br>";
>
> switch ($day) {
> case "Monday":
> print "<br>Day is $day - During<br>";
> $startdated = `date +%Y-%m-%d -d 'a week ago' ` ;
> break;
> case "Tuesday":
> print "<br>Day is $day - During<br>";
> $startdated = `date +%Y-%m-%d -d '8 days ago' ` ;
> break;
> }
>
> print "<br>Day is $day - After<br>";
>
> ?>
--
----------------
Brian A. Henning
strutmasters.com
336.597.2397x238
----------------
More information about the TriLUG
mailing list