Convert YYYYMM field to date format
I have a numeric field that is setup YYYYMM that I would like to convert to a date (201812 = 2018-12-01) . This data comes through workbench 5. I can't find a way to change the field to a date in ETL so I wanted to push it in from workbench. I tried a concatenate(Left(Period,4),'-',Right(Period,2),'-',01) so it would look like 2018-12-01 but received "identifier expected". So I tried pulling out the year and month in separate transformations. Year would be Left(period,4) which was fine Validating the transformation but received "Index and length must refer to a location within the string. Parameter name: length" running the job.
My guess is the syntax doesn't follow what I'm used to in SQL. Any help with my calculation? Thanks.
Best Answer
-
You can use STR_TO_DATE() but you will first need to convert it to a string:
STR_TO_DATE( CONCAT(`Period`,'01), '%Y%m%d')
You could do this as a beastmode or as part of a select statement in a MySQL data flow
“There is a superhero in all of us, we just need the courage to put on the cape.” -Superman0
Answers
-
You can use STR_TO_DATE() but you will first need to convert it to a string:
STR_TO_DATE( CONCAT(`Period`,'01), '%Y%m%d')
You could do this as a beastmode or as part of a select statement in a MySQL data flow
“There is a superhero in all of us, we just need the courage to put on the cape.” -Superman0 -
It's also possible that you have a row within your Period column that is less than 4 characters, which could also throw that error. Are there any nulls or values that wouldn't follow the format you specified? I ask because as far as I have experienced, the Workbench behaves syntactically the same as SQL Server Management Studio (SSMS), for example.
0 -
Thank you both for your answers. Yes there were zeros in my column. I am doing my first SQL dataflow to convert that column but am having difficulty with the steps. I've watched the videos which don't match what I'm seeing and the articles don't have enough detail.
I created a transform and it validates.
SELECT STR_TO_DATE(CONCAT(LEFT(Cast(`Period` AS CHARACTER),4),'-',RIGHT(Cast(`Period` AS CHARACTER),2),'-01'),'%Y-%m-%d') as Month,
sum(`Revenue`),
sum(`ReimbOtherCost`)FROM `vision_pr_summary`
GROUP BY `Period`I want to pull this for my Output Dataset. The instructions say to use the transform table's name but I don't see that anywhere. Help,please?
0 -
The table name is in the top left. (click on the pencil icon to change it)
“There is a superhero in all of us, we just need the courage to put on the cape.” -Superman0 -
That's what I can't find. This is the transform step.
0 -
Oh, would you please check that when you clicked the "Add Transform" button, you have selected the "Table" and not "Transform" option?
See attached for a reference.
1 -
You beat me to it @dthierjung
“There is a superhero in all of us, we just need the courage to put on the cape.” -Superman0 -
@ST_-Superman-_ I was actually on the post admiring your PhotoShop skills (Black Belt well deserved just for that detail), so I only stumbled upon the response incidentally lol.
0 -
Yes I did miss that detail. I have learned much. Thank you.
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 738 Beast Mode
- 57 App Studio
- 40 Variables
- 685 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 47 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 124 Manage
- 121 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive