Extracting the Date Based on a pattern
Hi All,
I am trying to extract the date from one column based on a pattern..For example in the table below
if the column orderstatus has a * in the beginning and then there is a date of the format mm/dd/yyyy then I need to extract that date as the soldorstockdate otherwise I need to extract the date from orddate as the soldorstockdate...Can you please let me know how to do this...
Thanks,
Arun
Best Answer
-
Yes no problem , no need to say WHEN again ... This way should clear out the error
CASE WHEN LEFT(`ORDERSTATUS`,1) ='*' OR `ORDERSTATUS` like '%BAM%' THEN DATE_FORMAT(RIGHT(TRIM(`ORDERSTATUS`),10),'%m/%d/%Y') ELSE DATE_FORMAT(`orddate`,'%m/%d/%Y') end
Domo Arigato!
**Say 'Thanks' by clicking the thumbs up in the post that helped you.
**Please mark the post that solves your problem as 'Accepted Solution'2
Answers
-
Hi @ozarkram
if always the date you need is present at the end of the string and the identifier is
*
then first check for that asterisk character present, then get the last 10 of the string converting it to date format mm/dd/yyyy else use the columnorddate
this beastmode should do the job
-- Name your beastmode Soldorstockdate CASE WHEN INSTR(`orderstatus`, '*') >= 1 THEN DATE_FORMAT(RIGHT(TRIM(`orderstatus`),10),'%m/%d/%Y') ELSE DATE_FORMAT(`orddate`,'%m/%d/%Y') END
Domo Arigato!
**Say 'Thanks' by clicking the thumbs up in the post that helped you.
**Please mark the post that solves your problem as 'Accepted Solution'0 -
- check for the * character in the string
- if present then get the last 10 characters from the strings (if always is the date at the end)
- convert it to a date format month , day and year
- if the character * is not present then use the other column
This beastmode should do the job
-- name your beastmode Soldorstockdate CASE WHEN INSTR(`orderstatus`, '*') >= 1 THEN DATE_FORMAT(RIGHT(TRIM(`orderstatus`),10),'%m/%d/%Y') ELSE DATE_FORMAT(`orddate`,'%m/%d/%Y') END
Domo Arigato!
**Say 'Thanks' by clicking the thumbs up in the post that helped you.
**Please mark the post that solves your problem as 'Accepted Solution'2 -
Hi @Godiepi ...Really appreciate you getting back!..Can you please let me know what is the error with below code:
CASE WHEN LEFT(`ORDERSTATUS`,1)='*' OR
WHEN `ORDERSTATUS` like '%BAM%'
THEN DATE_FORMAT(RIGHT(TRIM(`ORDERSTATUS`),10),'%m/%d/%Y')
ELSE DATE_FORMAT(`orddate`,'%m/%d/%Y')
end
0 -
Yes no problem , no need to say WHEN again ... This way should clear out the error
CASE WHEN LEFT(`ORDERSTATUS`,1) ='*' OR `ORDERSTATUS` like '%BAM%' THEN DATE_FORMAT(RIGHT(TRIM(`ORDERSTATUS`),10),'%m/%d/%Y') ELSE DATE_FORMAT(`orddate`,'%m/%d/%Y') end
Domo Arigato!
**Say 'Thanks' by clicking the thumbs up in the post that helped you.
**Please mark the post that solves your problem as 'Accepted Solution'2
Categories
- All Categories
- 2K Product Ideas
- 2K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 311 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 3.8K Transform
- 656 Datasets
- 115 SQL DataFlows
- 2.2K Magic ETL
- 812 Beast Mode
- 3.3K Visualize
- 2.5K Charting
- 80 App Studio
- 45 Variables
- 771 Automate
- 190 Apps
- 481 APIs & Domo Developer
- 77 Workflows
- 23 Code Engine
- 36 AI and Machine Learning
- 19 AI Chat
- AI Playground
- AI Projects and Models
- 17 Jupyter Workspaces
- 410 Distribute
- 120 Domo Everywhere
- 280 Scheduled Reports
- 10 Software Integrations
- 142 Manage
- 138 Governance & Security
- 8 Domo Community Gallery
- 48 Product Releases
- 12 Domo University
- 5.4K Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 114 Community Announcements
- 4.8K Archive