Laravel Carbon, retrieve today's date with weekday?

后端 未结 3 1033

I am using carbon to compare 2 dates with today\'s date, however I also have another field in a database called weekday which contains values like:

\'MO\' \'TU\' \'W

3条回答
  •  太阳男子
    2021-01-01 14:17

    I'm not sure that Carbon has such formatting, but what you could do is get the wekkday from a map of days and the current week day constant:

    $weekMap = [
        0 => 'SU',
        1 => 'MO',
        2 => 'TU',
        3 => 'WE',
        4 => 'TH',
        5 => 'FR',
        6 => 'SA',
    ];
    $dayOfTheWeek = Carbon::now()->dayOfWeek;
    $weekday = $weekMap[$dayOfTheWeek];
    

提交回复
热议问题