Forum Discussion

Srini1053's avatar
Srini1053
New Member
3 years ago
Solved

Convert Text Data Type to Date?

Hi All,

 

I am newbie here. I am trying to convert text data type to date, but i am getting an error. 

Could you please help me on this?

 

  • plse try this

    try
    Date.FromText("01/"&[Date], [Format="dd/M/yy", Culture="en-EN"]) otherwise 
    try Date.FromText("01/"&[Date], [Format="dd/MM/yy", Culture="en-EN"]) otherwise Date.From(DateTime.LocalNow())

    or

    try
    Date.FromText("01/"&[Date], [Format="dd/M/yy", Culture="en-EN"]) otherwise 
    try Date.FromText("01/"&[Date], [Format="dd/MM/yy", Culture="en-EN"]) otherwise null

     

10 Replies

  • plse try this

    try
    Date.FromText("01/"&[Date], [Format="dd/M/yy", Culture="en-EN"]) otherwise 
    try Date.FromText("01/"&[Date], [Format="dd/MM/yy", Culture="en-EN"]) otherwise Date.From(DateTime.LocalNow())

    or

    try
    Date.FromText("01/"&[Date], [Format="dd/M/yy", Culture="en-EN"]) otherwise 
    try Date.FromText("01/"&[Date], [Format="dd/MM/yy", Culture="en-EN"]) otherwise null

     

  • Hello Srini1053 

    you could filter on <> "YTD", so you get rid of all text. Then try again and it should work. 

     

    BR

    hashtag_pete 

    • Srini1053's avatar
      Srini1053
      New Member

      I tried filtered out YTD, but still getting an error.

       

      • mlsx4's avatar
        mlsx4
        Memorable Member

        Hi Srini1053 

         

        You must do first the step of filtering YTD and then change to date format. In the steps on the right, check the order 

  • Hello Srini1053 

    then you need to to a bit of conversion first. Add a 1 for the first of the month and change / to .

    The code would be the following, you just have to adapt the source

    let
        Source = Excel.CurrentWorkbook(){[Name="Tabelle1"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type text}}),
        #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Date] <> "YTD")),
        #"Custom" = Table.AddColumn(#"Filtered Rows", "Custom", each let splitDate = Splitter.SplitTextByDelimiter("/", QuoteStyle.None)([Date]) in Text.Combine({"1.", Text.Combine(splitDate, ".")}), type text),
        #"Parsed Date" = Table.AddColumn(#"Custom", "Parsed Date", each Date.From(DateTimeZone.From([Custom])), type date)
    in
        #"Parsed Date"

    hope it helps - if so, kudos and mark as solution are appreciated. 

     

    Hashtag_pete