You could create an array with all the weekdays in it so you can use the Key value pairs to count up/down depending on what day it is. So say it is indeed Saturday, that would be an index of 5, thursday would be 3 Which means you can subtract 2 days to get the last thursday.
Mar 15, 2017
10
Level 7
Carbon - get last weekday from date
Hey
How can I get the last weekday from a date with Carbon? I don't mean the last day of the week, but for example the last Thursday from 11.03 (Saturday) would be 09.03. And for 07.03 (Thuesday) it would be 02.03
Any ideas?
Thanks and regards,
Level 67
Something like:
$searchDay = 'Thursday';
$searchDate = new Carbon(); //or whatever Carbon instance you're using
$lastThursday = Carbon::createFromTimeStamp(strtotime("last $searchDay", $searchDate->timestamp));
1 like
Please or to participate in this conversation.