I am trying to find the same day of week from last month if today's date is Wednesday Oct 2nd 2019. I need to retrieve Wednesday Sept 4th 2019.
I am using Carbon and have tried subDays(30) and subMonth(1) but that obviously doesn't return the same week day.
SalesLogs::loadByDate(Carbon::now()->subMonth(1));
This code works as expected, however I am unable to work out how to make it find the same day of the week based on the prior month.
It's not super clear what you are trying to do, but I will take a shot at it. What about if you subtract a month, and then go to the next matching weekday?
$weekday = now()->dayOfWeek;
SalesLogs::loadByDate(now()->subMonth(1)->next($weekday));
Note: you can take advantage of Laravel's handy now() helper function, which is equal to Carbon::now(), but saves you from having to import Carbon.
Does that get you what you need?
Related
As far as I understood there's only now() function available in ni-fi expression language to get time. I can easily get 1st day of each month since it is a constant, but how can I get last day of a current month since it varies from month to month?
Thank you beforehand!
${now():format("yyyy-MM-32"):toDate("yyyy-MM-dd"):format("yyyy-MM"):toDate("yyyy-MM"):minus(86400000)}
//^now ^next month ^to date ^1st of next month ^minus 1 day
nifi should provide a function for that...
Until yesterday it worked perfectly showed me February and January, the two previous months but now it is showing me March and January:
This is the date of my computer recently:
This is the code:
I do not understand what is happening if some information is missing or they need something else I can provide it
When subtracting a month from the 29th of March, you would expect to get the 29th of February, which does not exist. So, PHP compensates this by counting the extra days. This way, the date becomes the 1st of march.
To avoid this problem, use the carbon constructor and instruct it to get the last month:
$lastMonth = new Carbon('first day of last month');
I want to use Date.WeekOfYear() Function to get Week Number for datetime values, but with a custom day as the start of the week (Let's say Saturday rather than Sunday). How is it possible in PowerQuery M?
You could use a conditional statement like this (adding 1 to the weeknumber if the day is saturday):
if Date.DayOfWeek([Date])=5 then Date.WeekOfYear([Date])+1 else Date.WeekOfYear([Date])
I'm working on the following query and cant figure out the final piece of it. I need my query to give me a result set between the previous business and the previous business day minus (-) 28 days. (e.g. date range between 10/28/2015 and 10/28/2015 -28) The query that I wrote so far is only giving me the -28th day (09/30/2015) and NOT a range in between the previous business day and the previous business day -28. My research shows a couple of different ways of doing it and so far none have worked for me.
SELECT SMBL, SUM(NET_FLOWS/1000000.00)
FROM HISTORY
WHERE DATE - 28 = DATE AND DATE = TO_DATE('10282015','MMDDYYYY')
AND SYMBOL IN ('AAA','BBB')
GROUP BY SMBL
First off, date ranges are easy using BETWEEN, so you do the quick solution:
WHERE DATE BETWEEN (SYSDATE-28) and (SYSDATE-1)
Then you realize your dates have time components, so to include all of yesterday and all of day-28 you need to:
WHERE DATE >= TRUNC(SYSDATE)-28
AND DATE < TRUNC(SYSDATE)
Then I look at your rule "previous BUSINESS day" and ask - what are your business days? On a Monday to go up to the previous Friday? Or Saturday? Or are you a 7-day-a-week business? How about statutory holidays? And is it 28 CALENDAR days back? Or 28 BUSINESS days?
Ahh business rules. The devil is always in those details....
I want to set the first day of week in Stanford NLP in time expression extraction. The default is Monday, I want to set Saturday as the first day of week.
I tried to change "Basic dates/times" section in defs.sutime.txt and setting SUNDAY = DayOfWeek(1);
but once I did, I got a wrong date extraction. Any advises ??
Thanks.
The ISO8601 standard specifies Monday as the first day of the week (see https://en.wikipedia.org/wiki/ISO_8601#Week_dates). So DayOfWeek(1) will always map to the concept of Monday. If you would like to have different notation for the day of week, you can remap the output to interpret the day of the week differently.