Data Factory - Getting last Saturday from a current date - azure-data-factory

How can I find the date of the last Saturday from a current date in ADF (set as a variable) ?
For example in SQL I can run this query and it will return the last Saturday:
but I don't want to create a lookup activity to connect to the database and run that query. I want to define it as a variable.
Is it possible to create a variable that always returns the last Saturday?
Kind regards

You can use below expression to get the last saturday always in set variable activity.
#FormatDateTime(addDays(subtractFromTime(utcnow(),dayOfWeek(utcnow()),'Day'),-1),'yyyy/MM/dd')
Set variable:
Result:

Related

Add dynamic content to pass a parameter to get last 03 days if today is Monday in Azure Data Factory

i want to pass dynamic content to a parameter in "Execute SSIS Package" to pass
If sysdate= monday then get last 3 days
Can someone help to build the content using functions or expression
Thanks
There are 2 ways you can achieve this.
Use an IF activity to first check if today is a Monday. You can use an expression like #equals(dayOfWeek(utcnow()),1) for a Monday check.
If true, get utcNow() - 3 days using a dynamic content of #adddays(utcnow('yyyy-MM-dd'),-3). You may need to change the format to what you need.
Easier and more efficient option, just schedule your pipeline to run every Monday. Then there is no need to check anything.

Azure Data Factory - Date Expression in component 'derived column' for last 7 Days

I am very new to Azure Data Factory. I have created a simple Pipeline using the same source and target table. The pipeline is supposed to take the date column from the source table, apply an expression to the column date (datatype date as shown in the schema below) in the source table, and it is supposed to either load 1 if the date is within the last 7 days or 0 otherwise in the column last_7_days (as in schema).
The schema for both source and target tables look like this:
Now, I am facing a challenge to write an expression in the component DerivedColumn. I have managed to find out the date which is 7 days ago with the expression: .
In summary, the idea is to load last_7_days column in target Table with value '1' if date >= current date - interval 7 day and date <= current date like in SQL.I would be very grateful, if anyone could help me with any tips and suggestions. If you require further information, please let me know.
Just for more information: source/target table column date is static with 10 years of date from 2020 till 2030 in yyyy-mm-dd format. ETL should run everyday and only put value 1 to the last 7 days: column last_7_days looking back from current date. Other entries must recieve value 0.
You currently use the expression bellow:
case ( date == currentDate(),1, date >= subDays(currentDate(),7),1, date <subDays(currentDate(),7,0, date > currentDate(),0)
If we were you, we will also choose case() function to build the expression.
About you question in comment, I'm afraid no, there isn't an another elegant way for. To achieve our request, Data Flow expression can be complex. It may be comprised with many functions. case() function is the best one for you.
It's very clear and easy to understand.

SSIS For Loop Container with Date Variable

I want to create a monthly package that executes a daily query at ODBC and writes an output file.
More specifically the query must be first executed for the first day of the previous month (e.g. '01/11/2018') then the next one ('02/11/2018') until the last day of the previous month ('30/11/2018').
The date variables are currently saved as Strings and I also want to have a string variable with Oracle date format to be inserted into the query. How should it be organised? Is there a way that I could use the string variables in the expressions?
Break it into parts as follows:
Declare variables to store previous month start and end date as follows:
start_date(datetime) = (DT_DATE)((DT_WSTR,4)YEAR(DATEADD("MM",-1,GETDATE()))+"-"+RIGHT("0"+(DT_WSTR,2)MONTH(DATEADD("MM",-1,GETDATE())),2)+"-01")
end_date(datetime) = DATEADD("D", -(DAY(GETDATE())),GETDATE())
Declare variable Counter(datetime)
Create a For loop container as follows :
Rest of the Data Flow Task should be there within For loop container, which will create output file. You can use the variable Counter in SQL to parameterize it
In fact, I figured out that all I wanted to use in my loop was the daypart of the date, so I created two extra int variables that contains:
1) the first day of the month (1)
2) the last day of the month (28,30,31)
I used those two variables at the For Loop Expressions and convert the index to string, so I could add it in the query. Possibly there will be a better way and it would be welcome.

Using Current Date Time in SAS

I am selecting the data from a table using a date string. I would like to select all rows that have a update time stamp greater than or equal to today.
The simplest way that I can think of is to put today's date in the string, and it works fine.
WHERE UPDATE_DTM >'29NOV2016:12:00'DT;
However, if I want to put something like today's date or system date, what should I put?
I used today(), but it returned all rows in the table. I am not sure if it's because today() in SAS refers to the date 1/1/1960? I also tried &sysdate, but it returned an error message seems like it requires a date conversion.
WHERE UPDATE_DTM > TODAY();
Any ideas? Your thoughts are greatly appreciated!
DATETIME() is the datetime equivalent of TODAY() (but includes the current time). You could also use dhms(TODAY(),0,0,0) if you want effectively midnight (or, for your example above, dhms(TODAY(),12,0,0) to get noon today).

Crystal Reports default value for parameter

I'm attempting to make the parameters for a Crystal Report more user-friendly for a client, who has requested that they be able to have the default values for a Start and End date parameter be the first and last day of the previous month.
I know how to use either a formula in CR or a stored procedure to produce these values, but I want to know if a variable can be used in the 'Default Value' setting for a parameter, or if it only allows for static entries. Does anyone know? Right now the user can set the date parameters to null and the stored procedure generates the data for the previous month on its own, but I thought it'd be nice if the date parameters actually displayed the dates that were being used as defaults. Thanks in advance!
You can do it, Try below process:
Create a parameter ?date with String datatype and take static and write two default strings as below:
First day of previous month
Last day of Previous month
Now go to record selection formula and write below code:
if ({?date}="First day of previous month") then
table.date=DateSerial(year(currentdate),Month(Currentdate)-1,1)
else if ({?date}="Last day of previous month")
then
table.date=Cdate(DateAdd("d",-1,DateSerial(year(currentdate),Month(Currentdate),1)))