Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How about</p> <pre><code>$firstFridayOfOcober = strtotime('first friday of october'); </code></pre> <p>Or turn it into a handy function:-</p> <pre><code> /** * Returns a timestamp for the first friday of the given month * @param string $month * @return type int */ function firstFriday($month) { return strtotime("first friday of $month"); } </code></pre> <p>You could use this with Zend_Date like this:-</p> <pre><code>$zDate = new Zend_Date(); $zDate-&gt;setTimestamp(firstFriday('october')); </code></pre> <p>Then <code>Zend_Debug::dump($zDate-&gt;toString());</code> will produce :-</p> <pre><code>string '7 Oct 2011 00:00:00' (length=19) </code></pre> <p>I'd say that's a lot simpler :)</p> <p><strong>Edit after some more thought:</strong></p> <p>A more generalised function may be of more use to you, so I'd suggest using this:-</p> <pre><code>/** * Returns a Zend_Date object set to the first occurence * of $day in the given $month. * @param string $day * @param string $month * @param optional mixed $year can be int or string * @return type Zend_Date */ function firstDay($day, $month, $year = null) { $zDate = new Zend_Date(); $zDate-&gt;setTimestamp(strtotime("first $day of $month $year")); return $zDate; } </code></pre> <p><strong>These days my preferred method is to extend PHP's <a href="http://www.php.net/datetime" rel="nofollow">DateTime object</a>:-</strong></p> <pre><code>class MyDateTime extends DateTime { /** * Returns a MyDateTime object set to 00:00 hours on the first day of the month * * @param string $day Name of day * @param mixed $month Month number or name optional defaults to current month * @param mixed $year optional defaults to current year * * @return MyDateTime set to last day of month */ public function firstDayOfMonth($day, $month = null, $year = null) { $timestr = "first $day"; if(!$month) $month = $this-&gt;format('M'); $timestr .= " of $month $year"; $this-&gt;setTimestamp(strtotime($timestr)); $this-&gt;setTime(0, 0, 0); var_dump($this); } } $dateTime = new MyDateTime(); $dateTime-&gt;firstDayOfMonth('Sun', 'Jul', 2011); </code></pre> <p>Gives:-</p> <pre><code>object(MyDateTime)[36] public 'date' =&gt; string '2011-07-03 00:00:00' (length=19) public 'timezone_type' =&gt; int 3 public 'timezone' =&gt; string 'UTC' (length=3) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload