Add weekdays to date in MySQL

I always seem to need to add weekdays to a date and there doesn’t ever seem to be a solution so here’s mine. This creates a function in your MySQL database that you can use within a statement:

DROP function if exists addWeekDays;
CREATE FUNCTION addWeekDays(startDate DATE, weekdays INT) RETURNS DATE
   WHILE weekdays > 0 DO
         SET startDate = DATE_ADD(startDate, INTERVAL 1 DAY);
         IF (DAYNAME(startDate) = 'Saturday') THEN SET startDate = DATE_ADD(startDate, INTERVAL 1 DAY); END IF;
         IF (DAYNAME(startDate) = 'Sunday') THEN SET startDate = DATE_ADD(startDate, INTERVAL 1 DAY); END IF;
         SET weekdays=weekdays-1;
   RETURN startDate;


some_date = addWeekDays(DATE(NOW()), 3);


After increasing our dev team and ever expanding codebase it only seemed natural to move from SVN and Review Board to Git using Bitbucket for pull requests (code reviews) and Jira to handle project tracking and assignment

PhpStorm IDE & Xdebug

Since getting to grips with PhpStorm my productivity has increased again, the main reason for this is the Xdebug support. I’m not sure how I’ve been managing up until now, there’s no way I could turn back. If you’ve not used Xdebug before, it saves you having to var_dump() or print_r() and exit() at the point you’re trying to analyse (and keep refreshing to see if you’ve fixed it). – All you need to do is click the gutter to add a breakpoint and next time you access your site in a browser (with the Xdebug extension installed) PHPStorm & Xdebug will pause the application right there and let you see what’s in all the variables.


Wow, well I thought jQuery was good, AngularJS seemed like it was going to have a steep learning curve when first taking a look but after spending an hour or two looking at the tutorial I can’t believe how much time it’s going to save!

The two-way data binding is amazing, no more using selectors to find out what a value has been changed to; If you change the value in the view (ng-model) it will change it in the corresponding $scope variable in the controller (and vice versa). DOM manipulation, see you later.

LAMP setup

Well, I’d definitely say that it’s worth having the same setup as your peers, all the nuances have been figured out and everyone can work together towards a common goal.

Most of the guys are using a Linux desktop with Ubuntu installed (as am I) which avoids having to use any virtual machines to run apache etc. MySQL Workbench handles all the DDL and DML you’re tasked with and NetBeans IDE for your PHP and Javascript.

NetBeans for me is a great tool over Aptana’s offering I started out with; I find it much more focused, especially with the SVN integration. Viewing the annotations on the line numbers are great to find out who has worked on different sections of the code.

Modify weekdays php 5.3

Recently I needed to add a certain amount of weekdays onto a date using php 5.3.

I wrote this simple function which has two parameters, the amount of weekdays I want to add and the date I want to add them to as an instance of DateTime as follows:

* @param int $weekDays
* @param DateTime $date
* @return DateTime
public function addWeekdaysToDateTime($weekDays, DateTime $date)
    $days = 0;

    //only increase the day count for weekdays
    while ($days < $weekDays) {
        $date->modify("+1 day");

        //if we're now on a weekday, increase the weekday counter
        if (!in_array($date->format("D"), ['Sat', 'Sun'])) {
    return $date;

LAMP Developer Team Lead

I’ve only been in my role for 1 year and 9 months but I’ve settled in well as a LAMP developer and I’m well chuffed to have been made a team lead (one of two)! The dev team has grown a bit since I started so it should make it easier for triaging, divvying out projects and handling code reviews etc. – Speaking of which, we’ve been using Review Board with great success so far. It’s got a really nice side-by-side view to display the diff which I find a bit easier on the eye than the ++ – – affair you normally get if you’re going command line.

SVN 1.6 Command Line Tools In OS X Mavericks


After updating my Macbook to OS X Mavericks I though it best to checkout any updates my fellow developers had done to the site since I last checked out. Opening up terminal and typing SVN update gave me a message saying I need to install Command Line Tools – It gave me a dialog box to install it there and then, very good I thought until I tried again after the install as it said my Mac had SVN 1.7 but my project was made using the older 1.6 and needed to be upgraded which isn’t feasible for me.

To roll back to 1.6 I moved svn out of /usr/bin to my Documents folder just incase I needed to move it back later with this (note the ~):

sudo mv /usr/bin/svn ~/Documents/svn_1.7

After this SVN 1.7 wouldn’t load so I could safely replace it with SVN 1.6 by firstly downloading the latest Xcode from the app store. After Xcode was installed I looked at ‘show package contents’ in finder, browsed through the folders and saw it had Subversion 1.6 included. To point my Mac towards this I needed to edit my /etc/paths file and include this new location as follows:

sudo vi /etc/paths

I then just needed to create a new line at the bottom by entering the new path as so:


After saving the changes and restarting I ran the following command which showed me I had SVN 1.6 installed!

svn help

SVN 6 Months In


After 6 months daily use of SVN – Subversion and being part of a team of 8 developers I can clearly see the benefit of using a software version control system. I can’t imagine how hard it would be to keep track of what’s going on if still using ftp.

A few simple commands and you can pull in other peoples changes to your machine or commit your own :

# svn update (downloads any updates made in the repository)
# svn commit (commits and uploads your local changes to the repository)
# svn info (gives you information about the repository)
# svn stat -u (shows you local and repository changes)

Taking A Hiatus

I’ve got myself a shiny new full time job as a LAMP Developer so I’m having a break from my freelance work for the moment whilst I delve deeper into OO PHP. I’ll be working with a mixture of PHP frameworks and technologies and will be part of a team of 8 developers so will be ditching FTP and going straight into SVN to manage version control. I’ll let you know how I get on.