convert string to date

arkiboys 9,706 Reputation points
2022-06-07T05:46:28.763+00:00

Hello,
In dataflow source, I receive the postdate column as string i.e.

20220530
20210422
20220605
...

In the filter transformation, how can I filter only for the postdate in the previous month?
for the above example I should get data for:
20220530
perhaps something like: between 1st of previous month and last day of previous month?

Thank you

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,623 questions
0 comments No comments
{count} votes

Accepted answer
  1. AnnuKumari-MSFT 34,556 Reputation points Microsoft Employee Moderator
    2022-06-07T09:37:23.76+00:00

    Hi @arkiboys ,
    Thankyou for using Microsoft Q&A platform and thanks for posting your question.

    As per my understanding about your query, you are trying to filter out previous month dates using Mapping dataflow. Please let me know if my understanding is incorrect.

    Here , we need to check two things - Year of the datecolumn should be the same year as Current Year and month should be current month -1 . I am using same dates provided by you in the query as source column value.

    209043-image.png

    • Use this expression in the first filter transformation to make sure year belongs to current Year: equals(year(toDate(postdate,'yyyyMMdd')),year(currentUTC()))

    209103-image.png

    • Use the following expression in next filter transformation to check the month belongs to the immediate previous month: equals(month(toDate(postdate,'yyyyMMdd')), month(currentUTC())-1)

    209055-image.png

    Hope this will help. Please let us know if any further queries.

    ------------------------------

    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you.
      Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
    • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators

1 additional answer

Sort by: Most helpful
  1. Subashri Vasudevan 11,226 Reputation points
    2022-06-07T10:21:14.387+00:00

    Hello @arkiboys

    Have a look at this expression if you would like to try one more way.

    substring(dtcol,1,4)==toString(year(currentDate("yyyy-MM-dd"))) && lpad(toString (month(currentDate("yyyy-MM-dd"))-1),2,'0')

    Lpad is done to manage the months getting converted without preceding 0 like 5,6 etc

    Please let us know for issues.

    Thanks.

    1 person found this answer helpful.
    0 comments No comments

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.