0

Fellow coders,

I'm trying to get the data from last month divided in weeks from the database, I have heard about Carbon but I have no idea on how implement carbon in my actual data.

Does anyone have an idea on how to do this?

I currently have

$currentDate = Carbon::now()->subWeek();
$agoDate = $currentDate->subDays($currentDate->dayOfWeek)->subWeek();

Which does return the useful date info. But I would love to see how it's executed with some dummy data

Kayelder
  • 155
  • 1
  • 2
  • 18
  • 1
    `GROUP BY CONCAT(WEEK(your_field), YEAR(your_field))`? Why do you need Carbon? – Ivanka Todorova May 01 '17 at 11:59
  • @IvankaTodorova Its for an hour registration system. For instance I've put in some dummy values for last week. What I have to do now is to create a dropdown menu in which multiple weeks are displayed. Might a user click on 24 - 4 - 2017 / 30 - 4 - 2017. then I need to retrieve the values from last week and display them on the page – Kayelder May 01 '17 at 12:02
  • I mean, isn't it better to use Carbon, and then to use the variables containing the Carbon data in my regular queries from Eloquent? – Kayelder May 01 '17 at 12:05
  • Or I might just be stupid – Kayelder May 01 '17 at 12:05
  • Carbon is for dates when you work with PHP, if you want to query data from your database, use sql. – Ivanka Todorova May 01 '17 at 12:07
  • I know... But I need to get data for every last week (maximum a month ago). Don't I need to use a Carbon function for that? Because I am really really inexperienced.. I would love some help if that's possible – Kayelder May 01 '17 at 12:08
  • http://stackoverflow.com/questions/1736010/how-to-group-by-week-in-mysql – Ivanka Todorova May 01 '17 at 12:14
  • Thanks for the link, i'll try to use raw sql in my Laravel app – Kayelder May 01 '17 at 12:16
  • Use can use `->groupBy(DB::raw('YOUR QUERY HERE'))`. – Ivanka Todorova May 01 '17 at 12:31
  • But even if I get the query to work. How will I be able to pass that data in Ajax so that when a value is selected in the dropdown, the correct values will be displayed – Kayelder May 01 '17 at 12:32

0 Answers0