Forum Discussion

JennyMilf's avatar
JennyMilf
Helper I
3 years ago

Convert text to Date

Hi everyone,

How can I convert Year-month from text to Date? 

I tried: YearMonth_Date = DATE(LEFT(Table[YearMonth], 4), RIGHT(Table[YearMonth], 2), 1) but it's not work

Thank you

 

 

7 Replies

  • jaweher899's avatar
    jaweher899
    Impactful Individual

    please try 

     

    YearMonth_Date = DATE(
    YEAR(DATEVALUE("01-" & RIGHT(Table[YearMonth], 2) & "-" & LEFT(Table[YearMonth], 4))),
    MONTH(DATEVALUE("01-" & RIGHT(Table[YearMonth], 2) & "-" & LEFT(Table[YearMonth], 4))),
    1
    )

  • Anonymous's avatar
    Anonymous
    Not applicable

    Could you give more of an explanation please? You already have activate date, then Year Month that i'm assuming comes from activate date. It look like you're trying to recreate activate date? I'm not sure what you're trying to do. 

    Could you give an example output. You may need to use CONVERT() to turn your string into a date format. Let me know and i'll get straight back to you 🙂 good luck

  • How about Month_hoa convert to Date (just show month number)?

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      =SWITCH([Month Name],"Jan",1,"Feb",2,"Mar",3,"Apr",4,"May",5,"Jun",6,"Jul",7,"Aug",8,"Sep",9,"Oct",10,"Nov",11,"Dec",12,"Invalid Month")

       
      Try this 🙂 
    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi JennyMilf 

      You can refer to the following calculated column:

       

      YearMonth_Date = CONVERT([Year-Month],DATETIME)
      
      Month_num=MONTH(CONVERT([Month_hoa]&" "&"1",DATETIME))
      

       

      Best Regards!

      Yolo Zhu

      If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

       

  • hi JennyMilf 

    what do you get with this:

    YearMonth_Date = DATE(LEFT(Table[YearMonth], 4), RIGHT(Table[YearMonth], 2), 1)

    ?