How does the _first_of_month (current_date) Cognos function work? - cognos

How does the _first_of_month (current_date) Cognos function work?
If the current date today is September 8, does it return all the value from September 1 to September 8? Month to date. Or does is return the value of the past month? Does it only return a value of 1 day?
So if I have a column CreatedDate then I use the function like this.
[CreatedDate]=_first_of_month (current_date)
This is an example of the CreatedDate column.

_first_of_month() takes a date value and returns a date value corresponding to the first day of the month of the value passed in.
Passing in: 2015-08-15 Returns: 2015-08-01
Passing in: 2014-03-21 Returns: 2014-03-01
Passing in: 1996-07-22 Returns: 1996-07-01
It's key to remember that the type of the return value will be another date.

Related

how to calculate the date from the year, week-of-year and day-of-week in EXCEL?

I have the Year, Week-of-Year and Day-of-the-Week as follows:
Year = 2022 (A2) ; Week Year = 35 (B2); Week Day = 4 or Thursday (C2)
and I would like to estimate the Date as dd.mm.yyyy, which is highlighted in yellow as it shows in the EXCEL picture.
I tried many formulas, but I am sure there might be an easy one.
I think you are counting the weeks starting from zero because for 9/1/2022 (YYYY/MM/DD format) the corresponding week is 36 as per the result of function WEEKNUM(DATE(2022,9,1)). In order to use the logic to multiply the number of weeks by 7. You need to use as a reference the first day of the year, if it was a Sunday, if not then go back to the previous Sunday, so you can count the entire week. Bottom line use as a reference date, the Sunday of the first week of the year, not the first day of the year (YYYY/1/1)
Here is the approach we use in cell E2:
=LET(y, A2:A6, wk, B2:B6, wDay, C2:C6, fDay, DATE(y,1,1), seq, SEQUENCE(7),
fDay - IF(WEEKDAY(fDay)=1,0, WEEKDAY(fDay,2)) + 7*wk
+ XLOOKUP(wDay, TEXT(seq,"dddd"), seq-1))
We use the LET function to avoid repeating the same calculation. The following expression finds the previous Sunday if the first day of the year (fDay) was not a Sunday:
fDay - IF(WEEKDAY(fDay)=1,0, WEEKDAY(fDay,2))
The XLOOKUP function is used to get the numeric representation of the weekday and use the TEXT function to generate the weekdays in a long format. Since we count the entire week, if the weekday is a Sunday (column C in my screenshot), then we don't need to add any day to our reference date, that is why we use seq-1.
Here is the output for several sample data. Assuming the week count starts with zero, if not the formula needs to be adjusted as also the input data.
Notice that the year 2021 started on a Friday, so if we want to find a day for the first week (0) before Friday it will return a date from the previous year. Like in the case of Monday. If you want an error message instead, then the formula can be modified as follow:
=LET(y, A2:A6, wk, B2:B6, wDay, C2:C6, fDay, DATE(y,1,1), seq, SEQUENCE(7),
result, fDay - IF(WEEKDAY(fDay)=1,0, WEEKDAY(fDay,2)) + 7*wk
+ XLOOKUP(wDay, TEXT(seq,"dddd"), seq-1),
IF(YEAR(result) <> y, "ERROR: Date from previous year", result))
I found the solution:
Year = 2022 (A2) ; Week Year = 35 (B2); Week Day = 4 or Thursday (C2)
=DATE (A2,1,3)-WEEKDAY(DATE(A2,1,3)) + 7 * B2 + C2 - 6
I found this solution, but you need to do further testing if it really works.
I calculate month from week: =+MONTH(DATE(YEAR(A2);1;1)+B2*7-1)
I calculate week day number from week day name: =MATCH(D2;{"Monday";"Tuesday";"Wednesday";"Thursday";"Friday";"Saturday";"Sunday"};0)
And then make date using: =DATE(A2;C2;E2)

How do I get the last day of the quarter date using Date and ceiling?

I want to get the date that is the last day of the quarter. Can you help me solve this?
I've taken over an old model and trying to understand the logic behind it. The quarter end date is formulated as follows:
A2=DATE(Year(A1),CEILING(MONTH(A1),3)+1,0) Where cell A1=2019-07-01.
This formula= 2019-09-30 which is the right date, but I'm having a hard time understanding the ceiling, multiplier and +1. I think the +1 is to get September (9) instead of August (8) but I don't understand why 3 as a multiplier returns 8 if it is not a multiplier of 3. Shouldn't it return 6 or 9?
Thank you so much for your help!
Let's break this into parts:
MONTH(A1): equals 7.
CEILING(7,3): equals 9.
CEILING(7,3)+1: equals 10.
YEAR(A1): equals 2019.
DATE(2019, 10, 0): equals 2019-09-30.
Using 0 as the day with DATE is the trick - October "0th" is actually September 30th.

How to get / output all days in the current week in Automation Anywhere?

I'm attempting to output all days within the current week. e.g. for this week, show all days, 05/12/2019 through 05/18/2019 only. when the bot is executed next week, only show days 05/19/2019 through 05/25/2019. My current logic outputs the days for this week, but come tomorrow, the dates for this week will be thrown off. Please see the following
...could I get some help with this please?
Using VBS
I would do this using a VBS script, using Run Script command.
The default week start is Sunday you can change it check: https://www.w3schools.com/asp/func_weekday.asp
Pass the day you that you want as a parameter from 0 to 6, and get the data as a return value.
DayNumber: 0 = Sunday ..... 6 = Saturday
InputDate = Date
DayNumber = WScript.Arguments.Item(0)
Result = DateAdd("d", DayNumber - WeekDay(InputDate, 2), InputDate)
WScript.StdOut.Write(Result)
'MsgBox(Result)
Using MetaBot
Metabot Link: Change Date and Time Format
You will have to run the following logic in sequence.
Input: DayNumber: 0 = Sunday ..... 6 = Saturday
Using DayOfWeek Logic, Get the Day of the week and assign it to
WeekDay variable, it will return the name, not the number, and the input will be Date.
Using IF conditions convert the name of
the day to number, start from 0 to 6 as your first day in the week,
which is Sunday, and using variable operation assigns the value to
NumWeekDay variable.
Using variable operation, Get the offset by subtracting DayNumber, the day you want minus NumWeekDay,
and assign the value to Offset variable.
Using AddDays, Input
the date and the offset, and you will get the date of the day that you want.

Search for particular format of date in saved search

I'm trying to find the customers whose birthday is in next month and the way the birthdays of customers will be entered at the stores is, they just ask for day and month and put in the current year for year.
So, when I', trying to do the search as next month it seem like I can only search with in a range that include year, which don't work in this case.
I've tried the below with search field set to is february but it don't automate the search as I have to change the month every month
TO_CHAR({custentity_spos_date1},'MONTH, YYYY')
Does some one have any idea how to include only month in search so that I can search for customers who's birthday is in a particular month?
case
when to_char({today}, 'MM') = '12' then
case
when to_char({custentity_spos_date1}, 'MM') = '01' then 1
else 0
end
when to_number(to_char({custentity_spos_date1}, 'MM')) = to_number(to_char({today}, 'MM')) + 1 then 1
else 0
end
equal to 1
The filter basically says if the month of the current date is 12, then match any record where the month of the date field is 1, otherwise match any record where the month of the date field is equal to the month of the current date + 1.
There may be an easier way, but this worked for me.
You can use the SQL formatting and ADD_MONTHS functions to compare only the month component of the date:
CASE WHEN TO_CHAR({custentity_spos_date1}, 'MM') = TO_CHAR(ADD_MONTHS(sysdate, 1),'MM') THEN 1 ELSE 0 END
Equal to 1.

Wrong number of days Excel

I am trying to calculate the difference between days but receiving the wrong number of total days for that year. For the dates 2016-01-01 and 2016-12-31 I receive 365 days but not 366. I used the following function where I receive the same output:
=DAYS("2016-12-31","2016-1-1")
=DATEDIF("2016-1-1","2016-12-31","d")
="2016-12-31"-"2016-1-1"
I am not sure what I am doing wrong? Soemhow the leap year's are not properly accounted for.
I think you are misinterpreting the output from the DATEDIF function. Consider the following function call:
=DATEDIF("2016-12-30", "2016-12-31", "d")
This returns 1, which is the number of days between the two dates. Similarly, the following call returns 365:
=DATEDIF("2016-01-01", "2016-12-31", "d")
A value of 365 means that there are 365 days between the first day of the year (day #1, January 1), and the 366 day of the year (day #366, December 31).
As a sanity check, run the following:
=DATEDIF("2015-01-01", "2015-12-31", "d")
This returns 364 days, because 2015 was not a leap year and had no February 29 in its calendar.
Note that the end date must always be greater than the start date, otherwise you will get the #NUM! error. The call you made in your question will not even work.

Resources