Development

David Carr

Working with bank holidays with a Carbon wrapper

Working with dates in php is easy but working with bank holidays is a little more involved thankfully there is an awesome Carbon class that makes it super easy!

Getting setup requires composer:

composer require citco/carbon

Then to use it import it:

use Citco\Carbon;

Then you can initialise it and use it like this:

// Creates a new instance of the class
$c = new Carbon(); // Today's date

Get an array of bank holidays:

// Returns array of holidays for the given year
$c->getBankHolidays(2017);

To check if a date falls on a bank holiday it’s as simple as:

$boolean = $c->isBankHoliday('2017-03-28');

Returns the event when it’s a bank holiday and null for any other day.

Get the library from https://github.com/citco/carbon

 

Domains are often purchased from multiple providers, keeping track of where a domain is and its DNS settings can be tricky. Domain Mapper solves this by listing all your domains in one place. View your DNS settings and receive reminders to renew your domains. Try it today.

Support my work by donating with PayPal.

Subscribe to my newsletter

Subscribe and get my books and product announcements.

© 2009 - 2021 DC Blog. All code MIT license. All rights reserved.