I need to convert a text column to date in ETL

Options

and I am not sure how to do this, I have attached a screenshot of my text date

Best Answers

  • MichelleH
    MichelleH Coach
    Answer ✓
    Options

    @Sbhatia If you add an Alter Columns tile to the ETL you can change the data type of your date field from text to date. You can read more about this tile in this Knowledge Base article: https://domo-support.domo.com/s/article/360044876874?language=en_US

  • GrantSmith
    GrantSmith Coach
    Answer ✓
    Options

    If you have garbage data which doesn't match your date format ('Day' in your example) it may not be simple enough to just convert it to a date. You may need to conditionally set your date value:

    CASE WHEN REGEXP_LIKE(`date_field`, '^\d{4}-\d{2}-\d{2}$') THEN
      STR_TO_DATE(`date_field`, '%Y-%m-%d')
    END
    

    **Was this post helpful? Click Agree or Like below**
    **Did this solve your problem? Accept it as a solution!**
  • MarkSnodgrass
    Answer ✓
    Options

    You can also use TRY_CAST(myfield as date) this will null the value if it can't convert it to a date, otherwise it will make it a date formatted value.

    **Check out my Domo Tips & Tricks Videos

    **Make sure to <3 any users posts that helped you.
    **Please mark as accepted the ones who solved your issue.

Answers

  • MichelleH
    MichelleH Coach
    Answer ✓
    Options

    @Sbhatia If you add an Alter Columns tile to the ETL you can change the data type of your date field from text to date. You can read more about this tile in this Knowledge Base article: https://domo-support.domo.com/s/article/360044876874?language=en_US

  • GrantSmith
    GrantSmith Coach
    Answer ✓
    Options

    If you have garbage data which doesn't match your date format ('Day' in your example) it may not be simple enough to just convert it to a date. You may need to conditionally set your date value:

    CASE WHEN REGEXP_LIKE(`date_field`, '^\d{4}-\d{2}-\d{2}$') THEN
      STR_TO_DATE(`date_field`, '%Y-%m-%d')
    END
    

    **Was this post helpful? Click Agree or Like below**
    **Did this solve your problem? Accept it as a solution!**
  • pauljames
    pauljames Contributor
    Options

    @Sbhatia I run into this all the time. The magic etl tile has let me down far too often. I'd definitely give Grants recommendation a try. Sometimes you have to do this conditional step.

    IF I SOLVED YOUR PROBLEM, PLEASE "ACCEPT" MY ANSWER AS A SOLUTION. THANK YOU!

  • MarkSnodgrass
    Answer ✓
    Options

    You can also use TRY_CAST(myfield as date) this will null the value if it can't convert it to a date, otherwise it will make it a date formatted value.

    **Check out my Domo Tips & Tricks Videos

    **Make sure to <3 any users posts that helped you.
    **Please mark as accepted the ones who solved your issue.