Skip to content

Instantly share code, notes, and snippets.

@dhrrgn
Created January 17, 2013 18:24
Show Gist options
  • Save dhrrgn/4558241 to your computer and use it in GitHub Desktop.
Save dhrrgn/4558241 to your computer and use it in GitHub Desktop.
Easily accept a date range with Laravel and Carbon
<?php
// By default the range will be the last 30 days (including today)
$start = Input::has('start') ? new Carbon(Input::get('start')) : Carbon::now()->subDays(29);
$end = Input::has('end') ? new Carbon(Input::get('end')) : Carbon::now()->addDay();
// I use toDateTimeString() here which is a MySQL DateTime string,
// you can use whatever you like obviously.
$start = $start->startOfDay()->toDateTimeString();
$end = $end->startOfDay()->toDateTimeString();
@mamulasa
Copy link

Thanks for sharing. How can I get the range for 7 days. Starting on mondays to sundays?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment