Created
January 17, 2013 18:24
-
-
Save dhrrgn/4558241 to your computer and use it in GitHub Desktop.
Easily accept a date range with Laravel and Carbon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing. How can I get the range for 7 days. Starting on mondays to sundays?