Home Data Prep Q&A

Paxata Community Members: Something special in a community experience is coming your way. Stay tuned to this space.
In the meantime, check out the brand new Data Prep for Data Science topic here and the new DataRobot Community.

Visit the official Paxata Documentation portal for all of your doc needs.

How to convert date from month and year?

Hi all,

I have imported the data and I have columns Month and year. (Year :  2019, 2020 etc.) and Column "Month" (string format - like "Jan", "Feb", etc.).

Now I need to create new column with acceptable date from these two columns. e.g. if I use from "Year" - 2019 and from "Month" - Nov, I need to get 11/1/2019 and so on.

Can someone help me with this?

Thank you in advance.

Regards,

Praveen



Answers

  • Hi Praveen,

    You can use a computed column (let's call it New_Date) with the following expression:

    @[email protected] + "/1/" + @[email protected]

    Alternatively, you can also use concatenate function as well (provided as part of computed column functions):

    CONCATENATE(@[email protected], "/1/", @[email protected] )

    If you are planning to use "New_Date" for date-related logic then it's a good idea to convert it into a date.

    I hope this helps,

    With Best Regards
    Sudheer Kumar 
  • Hi Sudheer,

    I am getting error for the following formula :

    DATE(@[email protected]+ "/1/" + STR(@[email protected]))
     ↳ Expected three arguments

    Regards,
    Praveen
  • Hi Praveen,

    The function DATE expects a numeric or integer inputs. Day value should be just 1 not "/1/". You need to convert any string values to numeric. The details from our context help are shown below:

    DATE
    Takes three separate arguments and combines them to form a date in a new DateTime column.
    Syntax:

    DATE(YEAR, MONTH, DATE)

    • YEAR is four-digit value
    • MONTH is two-digit value
    • DATE is two-digit value
    Example:

    DATE(@[email protected], @[email protected], @[email protected])

    Notes on use:Leading zeros for MONTH and DATE are not supported, for example:
    DATE(1999,05,08) should be expressed as DATE(1999,5,8)


    With Best Regards
    Sudheer Kumar
Sign In or Register to comment.