Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added a function to Date Helper to find the last weekday in a given month/year. #1842

Closed
wants to merge 1 commit into from

4 participants

@BradEstey

Meh, It's kind of useful..

@ckdarby

I am having a hard time seeing the use case outside of your own application...maybe I am wrong on this but I haven't had any need for this function...

@narfbg
Owner

I agree with @ckdarby on this one. Anybody else care to comment?

@alexbilbie

I agree too, it's a feature for the sake of a feature.

Sorry @BradEstey. Maybe you could make a Gist and add it to the wiki?

@alexbilbie alexbilbie closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 2, 2012
  1. @BradEstey
This page is out of date. Refresh to see the latest.
Showing with 36 additions and 0 deletions.
  1. +36 −0 system/helpers/date_helper.php
View
36 system/helpers/date_helper.php
@@ -299,6 +299,42 @@ function days_in_month($month = 0, $year = '')
}
// ------------------------------------------------------------------------
+
+if ( ! function_exists('last_weekday_in_month'))
+{
+ /**
+ * Last weekday in the month
+ *
+ * Takes a month/year as input and returns the last weekday
+ * for the given month/year.
+ *
+ * @access public
+ * @param integer a numeric month
+ * @param integer a numeric year
+ * @return integer
+ */
+ function last_weekday_in_month($month = 0, $year = '')
+ {
+ $days_in_month = days_in_month($month, $year);
+
+ if ( ! $days_in_month)
+ {
+ return 0;
+ }
+
+ $last_day = date('N', strtotime($year.'-'.$month.'-'.$days_in_month));
+
+ while ($last_day > 5)
+ {
+ $days_in_month--;
+ $last_day--;
+ }
+
+ return $days_in_month;
+ }
+}
+
+// ------------------------------------------------------------------------
if ( ! function_exists('local_to_gmt'))
{
Something went wrong with that request. Please try again.