subtract 2 day current date in ADF - azure

I am usig azure data factory and basically I need to add a dynamic content (date function) to do this:
SELECT DATEADD(DAY, -2, GETDATE())
any idea?

I guess you can do the below using Logical Function
#equals(formatDateTime(addDays(utcnow(),-2),'yyyy-MM-dd'),formatDateTime(activity('Your Metadata Activity Name').output.lastmodifieddate,'yyyy-MM-dd'))

You can use just addDays() function to get date differences. Detailed document on Azure Data Factory expressions and function is available : here
I used #{formatDateTime(convertfromutc(addDays(utcNow(),-6),'Eastern Standard Time'), 'yyyy-MM-dd' )} Here I wanted to get 6 days old date (from current date).

If Date contains timestamp then you should try below code.
#string(addhours('2022-08-03 06:20:51',-2, 'yyyy-MM-dd HH:mm'))

Related

Cognos scheduled report e-mail with current date

I want to schedule the mailing of a Cognos report, always using the current date. So, for example: today, I want to e-mail the report with data up until the 28th, but tomorrow it should contain data up until the 29th.
How can I achieve this?
Thanks in advance!
If you're expecting code, you didn't provide enough information, but let me try...
Assuming the "date" data against which you want to filter is in a query item named [Date] which is in a query subject named [Time] which is in a namespace named [namespace], create a filter like this:
[namespace].[Time].[Date] = current_date
If you want up to the current date which includes the days leading up to it you can use what dougp posted slightly modified.
[namespace].[Time].[Date] <= current_date
to ensure the where clause is pushed down to the database, I personally like to use a macro for current_date. So the expression becomes
[namespace].[Time].[Date] <= # timestampMask ( $current_timestamp , 'yyyy-mm-dd' ) #

Getting dates for historical data copy in Azure datafactory

I have to copy historical data from a rest api for one year eg., from March 1,2019 to March1,2020.The Rest API takes a start and end date as params.
To prevent load, however I have to call the API in pieces like copy with the start and end date as March1,2019 to March 30,2019....Once thats done then April 1,2019 to april 30,2019 and so on till March 1 ,2020 automatically and without manual intervention.
I was able to use utc now and add days for copying data for previous day to current startofday but am unable to figure out the copy of historical data.Any idea if this is possible?
You can try something like this:
1.create two variable named start_date and end_date.
2.create a Until activity, and type this expression:#greaterOrEquals(variables('end_date'),'2020-03-01T00:00:00Z')
3.create a Copy activity
Source setting:
Source dataset:
Sink dataset:
4.create tow Set variable activity to change start_date and end_date
Result:
By the way, you can change your date format according you need. Reference https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings.

Specify datetime2 format in Azure SQL data warehouse (synapse)

What is the correct way to specify the format of a datetime2 field when creating a table in Azure SQL data warehouse? I don't seem to be able to find an example in the documentation.
The data looks like this:
"2020-09-14T20:50:48.000Z"
CREATE TABLE [Foo].[Bar](
...
MyDateTime datetime2(['YYYY-MM-DDThh:mm:ss[.fractional seconds]')
)
As Panagiotis notes, the underlying representation is an int/long for the actual date value. This is how RDBMS engines can quickly compute the delta between two dates (days between Monday and Friday is a simple subtraction problem). To answer your question, you simply would format your create table as:
CREATE TABLE [Foo].[Bar](
...
MyDateTime datetime2
)
If you're interested in formatting the result in a query, you can look to the CONVERT or FORMAT functions. For example, if you wanted the format dd-mm-yyyy (Italian date), you could use either of the following:
SELECT
CONVERT(VARCHAR, CURRENT_TIMESTAMP, 105)
, FORMAT(CURRENT_TIMESTAMP, 'dd-MM-yyyy')
Note: CONVERT is generally faster than FORMAT and is the recommended approach if you have a date format that is supported. This is because the FORMAT function relies on the CLR which will include a context/process jump.

How to Convert a column having one timestamp to another timestamp in Azure Data Factory

I have column ABC where timestamp is of format dd/MM/yyyy HH:mm:SS (11/04/2020 1:17:40).I want to create another column ABC_NEW with same data as old column but with different timestamp 'yyyy-MM-dd HH:mm:SS'.I tried doing in azure data factory derived column using
toTimestamp(column_name,'yyyy-MM-dd HH:mm:SS') but it did not work it is coming as NULL. Can anyone help?
It's a 2-step process. You first need to tell ADF what each field in your timestamp column represents, then you can use string conversions to manipulate that timestamp into the output string as you like:
toString(toTimestamp('11/04/2020 1:17:40','MM/dd/yyyy HH:mm:ss'),'yyyy-MM-dd HH:mm:SS')
Data Factory doesn't support date format 'dd/mm/yyyy', we can not convert it to 'YYYY-MM-DD' directly.
I use DerivedColumn to generate a new column ABC_NEW from origin column DateTime and enter the expression bellow:
toTimestamp(concat(split(substring(DateTime,1, 10), '/')[3], '-',split(substring(DateTime,1, 10), '/')[2],'-',split(substring(DateTime,1, 10), '/')[1],substring(DateTime,11, length(DateTime))))
The result shows:
This is a trick which was a blocker for me, but try this-
Go to sink
Mapping
Click on output format
Select the data format or time format you prefer to store the data into the sink.

How do I query for a specific day such as yesterday in Core Data?

In plain SQL (in my case: sqlite), I would be able to query for a specific date in a DATE column as follows:
SELECT * FROM table WHERE date(dateColumn) = '2015-01-01'
This works because the date() function cuts off the time part of the DATE value.
Can I do something similar with Predicates in Core Data? Or do I have to use something where I determine the start and end of that day and then look for dates between the two date values?

Resources