Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not the most versatile solution, but this actually does EXACTLY what you want to do:</p> <p>Class:</p> <pre><code>&lt;?php class validate { private static $month; private static $year; private static $day; private static $day_literal; function __construct() { self::$year = date("Y"); self::$month = date("m"); self::$day = date("d"); self::$day_literal = date("l"); } public function firstInMonth($required,$day,$month,$year) { $firstday; for ($i = 1; $i &lt; 31; $i++) { if (checkdate($month,$i,$year)) { if (trim(strtolower(date("l",mktime(0,0,0,$month,$i,$year)))) == trim(strtolower(trim($required)))) { $firstday = $i; break; } else { continue; } } } if (strtotime(date("Y-m-d",mktime(0,0,0,$month,$i,$year))) == strtotime(date("Y-m-d",mktime(0,0,0,$month,$day,$year)))) { return "{$year}/{$month}/{$day} is the first {$required} of the month."; } else { return "Nope."; } } public function checkDayLiteral($literal,$day,$month,$year) { if (trim(strtolower(date("l",mktime(0,0,0,$month,$day,$year)))) == trim(strtolower($literal))) { return true; } else { return false; } } public function dayPosition($day,$month,$year) { return date("jS",mktime(0,0,0,$month,$day,$year)); } } ?&gt; </code></pre> <p>I don't know what's the purpose of your checking, so I've also implemented the construct method to compile the "today" values, which are NOT used in the code. If you need them, feel free to call them using self::</p> <p>How to use:</p> <pre><code>&lt;?php $validate = new validate; echo $validate-&gt;firstInMonth("Monday",2,9,2013); echo "&lt;br /&gt;"; echo $validate-&gt;checkDayLiteral("Monday",2,9,2013); echo "&lt;br /&gt;"; echo $validate-&gt;dayPosition(2,9,2013); ?&gt; </code></pre> <p>Change the class according to WHAT you need to get (I mean: edit the returns I've set).</p> <p>In this case, the above code returns:</p> <blockquote> <p>2013/9/2 is the first Monday of the month.</p> <p>1</p> <p>2nd</p> </blockquote> <p>while this:</p> <pre><code>echo $validate-&gt;firstInMonth("Tuesday",2,9,2013); echo "&lt;br /&gt;"; echo $validate-&gt;checkDayLiteral("Wednesday",15,9,2013); echo "&lt;br /&gt;"; echo $validate-&gt;dayPosition(24,9,2013); </code></pre> <p>returns this:</p> <blockquote> <p>Nope.</p> <p>24th</p> </blockquote> <p>Of course, this is not as versatile as whatever you want, but this works.</p> <p>Hope this helps.</p> <p>If it does not do exactly what you want I'm sorry, just take this as an idea, I think it's pretty clear how you can get whatever information you want from this code.</p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    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