question

Jay-8106 avatar image
0 Votes"
Jay-8106 asked KranthiPakala-MSFT commented

ADF Expression for Previous Date with Time set to 0

I need to get the previous days date and I have a parameter : paramDays = -1

And this expressions : @adddays(startOfDay(utcnow()),pipeline().parameters.paramDays)

But looks like it is giving me a time of 1am.

What is the best way to always make sure time returned is 00:00

azure-data-factory
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

KranthiPakala-MSFT avatar image
0 Votes"
KranthiPakala-MSFT answered KranthiPakala-MSFT commented

Hi @Jay-8106,

Thanks for reaching and posting your query.

You dynamic expressions looks good and it should return the start of day (for eg: "2018-03-15T00:00:00.0000000Z") since your are using startOfDay function

104303-image.png


I did tested your expression as-is and the result is as expected. Please see below GIF

104248-startofday.gif

Here is the sample pipeline json payload, in case if you would want to retest or play around it.

 {
     "name": "pipeline5",
     "properties": {
         "activities": [
             {
                 "name": "Set variable Hardcoded value",
                 "type": "SetVariable",
                 "dependsOn": [],
                 "userProperties": [],
                 "typeProperties": {
                     "variableName": "varTime",
                     "value": {
                         "value": "@adddays(startOfDay(utcnow()),-1)",
                         "type": "Expression"
                     }
                 }
             },
             {
                 "name": "Set variable Parameter",
                 "type": "SetVariable",
                 "dependsOn": [],
                 "userProperties": [],
                 "typeProperties": {
                     "variableName": "varTime2",
                     "value": {
                         "value": "@adddays(startOfDay(utcnow()),pipeline().parameters.paramDays)",
                         "type": "Expression"
                     }
                 }
             }
         ],
         "parameters": {
             "paramDays": {
                 "type": "int",
                 "defaultValue": -1
             }
         },
         "variables": {
             "varTime": {
                 "type": "String"
             },
             "varTime2": {
                 "type": "String"
             }
         },
         "annotations": []
     }
 }

Hope this helps. In case if you see a different behavior, could you please share your pipeline JSON payload and the screenshot of output you are receiving?



Please don’t forget to Accept Answer and Up-Vote wherever the information provided helps you, this can be beneficial to other community members.





image.png (50.1 KiB)
startofday.gif (2.3 MiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks I'll take another look, expression is used in a stored procedure if that would make a difference at all.

104333-image.png


0 Votes 0 ·
image.png (10.4 KiB)

Hi @Jay-8106,

I don't think that would make a difference. The output from dynamic expression remains same. Please have another look and let us know how it goes. Were you able to see what was the value passed to GTEDate parameter? I would recommend validating again. Please do simple test with a set variable activity to make sure your expression is returning the expected value.

Do let us know how it goes.

Thanks

0 Votes 0 ·

Hi @Jay-8106,

Following up to see if you still need assistance on this query. In case if you have already found a different solution, please do consider to share it here with community, as it would be helpful for others reading this thread. And if you have further query, do let us know.

0 Votes 0 ·