Previous day excluding only Saturdays with php Carbon - php-carbon

I'm trying to get the previous day excluding Saturdays using Carbon, but I can only find how to get previous date excluding weekends.
So with:
$todayDate = Carbon::now();
$dayBefore = $todayDate->subWeekDay();
if today is Monday in $daybefore I get Friday, but I need Sunday and if today is Sunday I need Friday...
I can't find a way to exclude only Saturdays from day before.
nesbot/carbon => 2.41.5

Finally I got the previous day excluding saturdays like this:
$dayBefore = Carbon::yesterday();
if ($dayBefore->isSaturday()) {
$dayBefore = $dayBefore->subDay();
}

Related

Get Monday of last week with JodaTime

I need get Monday of last week E.g
Today is 28/11/18 (wednesday)
I need get 19/11/18 (monday)
I know that I can obtain Monday of the current week with
val monday = DateTime().withDayOfWeek(DateTimeConstants.MONDAY)
I get it!
DateTime().withWeekOfWeekyear(
DateTime().weekOfWeekyear-1)
.withDayOfWeek(DateTimeConstants.MONDAY)
I only have to get the week of the year and subtract one week and that is all

Informix SQL to get date range that changes automatically

Please help me with an Informx SQL query to be run every Friday.
Period: 1st of the Month to the Thursday before the Friday that it is being run on. I can't just choose date ranges as it will be an auto report so the dates needs to update automatically. Is there a way to do this?
You've got two issues: the start of the month and the date of last Thursday. The simplest expression to identify the 1st day of the current month is:
MDY(MONTH(TODAY), 1, YEAR(TODAY))
The way to identify the most recent Thursday is via a CASE statement on WEEKDAY(TODAY). Something like:
CASE
WHEN WEEKDAY(TODAY) < 5 -- (Sunday (0) - Thursday (4))
THEN TODAY - WEEKDAY(TODAY) - 3 -- Calc last Sunday, back 3 days
ELSE TODAY - WEEKDAY(TODAY) + 4 -- Calc last Sunday, forward 4 days
END
Note, you will still run into issues where the 1st of current month is later than the most recent Thursday. But hopefully the examples above will point you in the right direction.
Of course, if you know this report is only ever going to be run on Fridays, then calculating the most recent Thursday is just TODAY -1.

Skip weekends Business day tasks NetSuite

Using NetSuite, I am trying to automate the creation of monthly tasks. These tasks will fall on the last day of the month, a day before, and 1,2,3,4,5 days after the last day of the month. But, the tasks can't be due on a weekend, only business days. So if the day falls on a sat or sun the dates have to move up. How can I use my custom record to calculate the next months task dates skipping weekends? Here is a screenshot of the record - see that 10/4 and 10/5 fall on saturday and sunday, how can I have it skip sat and sunday? I used the sql function option to generate the dates and days of the week.
I tested the following formula. Replace custbody_date with your field name. This formula should be set in your 'next month' column.
CASE WHEN INSTR(to_char({custbody_date}, 'DAY'),'SATURDAY') != 0
THEN {custbody_date}+2
WHEN INSTR(to_char({custbody_date}, 'DAY'),'SUNDAY') != 0
THEN {custbody_date}+1 ELSE {custbody_date}
END
This should also give you an idea to set the value for 'Next Month Day' (skipping saturday and sunday).

create week function, but instead of Sunday start day of the week, Monday

Anyone know of a script, that creates a week table, that is based on Monday as the start day of the week and not Sunday? For MS SQL
You can adjust the way SQL Server sets the first day of the week using http://msdn.microsoft.com/en-us/library/ms181598.aspx if that helps?
Basically this is putting every sunday to the week before, with week=0->week=52

Rails 3 Finding day of week

I'm trying to make my own calendar because i cant seem to get any help with event calendar so what im trying to do is Display the day of the week ie.. January 1 2011 is a Saturday is there an easy command to get that day or do i need something else
You can also get the string, like "Wednesday", using time.strftime("%A")
Can't you use time.wday, 0 = sunday and so on
Actively using in Rails 4 - should in most other versions as well...
Both of these options will give you the day string (eg. "Saturday") for the date specified:
Specific date:
Date.new(2011, 1, 1).strftime('%A') # returns "Saturday"
Today:
Date.today.strftime('%A')
If you're attempting to write your own calendar from scratch and want to write a function to do day lookup, you might want to check out Conway's Doomsday Algorithm, which is an interesting method for determining the day of the week on any given date. Otherwise the standard time class has a wday method which returns a number from 0-6 (0 is Sunday, 1 is Monday, etc).
We can use Time.now.utc.wday to get day of week without considering zone.
No need to use the Time class. date.cwday will return 1 for Monday, 2 for Tuesday etc.