ADF Expression for Previous Date with Time set to 0

Jay 561 Reputation points
2021-06-10T12:03:33.37+00:00

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
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
10,561 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. KranthiPakala-MSFT 46,462 Reputation points Microsoft Employee
    2021-06-10T13:51:57.893+00:00

    Hi @Jay ,

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.