How to convert month to text?

convert text format for month

PO Num PO Date Month
27000067 06-08-2024
24000168 21-08-2024
24000149 08-08-2024
24000146 06-08-2024
24000139 02-08-2024
24000146 06-08-2024
50000094 08-08-2024
50000040 20-06-2024
50000103 21-08-2024
50000094 08-08-2024
22000055 13-07-2024

Hi @domsmgtmeet22

Your query is confusing could you share the expected output also for our better understanding.

Hope you understand!!

Hie @domsmgtmeet22 could you please share the output result ?? Like where you get the input data for the month …
cheers Happy Automation

If this is what you meant , then assign the given date in string format to a date time variable( dt) as in the expression editor. Then the expression in the message box will you the month.

Thank you

DateTime.ParseExtract("21-08-2024","dd-MM-yyyy",System.Globalization.CultureInfo.Invariant.Culture).ToString("MMMM")

Regards,
Arivu

i want to need to need this output

PO Num PO Date Month
27000067 06-08-2024 Aug
24000168 21-08-2024 Aug
24000149 08-08-2024 Aug
24000146 06-08-2024 Aug
24000139 02-08-2024 Aug
24000146 06-08-2024 Aug
50000040 20-06-2024 June

i need this out put

PO Num PO Date Month
27000067 06-08-2024 Aug
24000168 21-08-2024 Aug
24000149 08-08-2024 Aug
24000146 06-08-2024 Aug
24000139 02-08-2024 Aug
24000146 06-08-2024 Aug
50000040 20-06-2024 June

Hi @domsmgtmeet22 ,

I have replicated your scenario, and below is the detailed solution

Input :
A table contains purchase order numbers, their corresponding dates, and an empty "Month" column. (Captioned by AI)

Output :
image

Below is the Code :

(From row In dt_Input.AsEnumerable 
Where Not String.IsNullOrEmpty(row("PO Date").tostring)
Let dateCol = DateTime.ParseExact(row("PO Date").ToString, "MM/dd/yyyy hh:mm:ss", System.Globalization.CultureInfo.InvariantCulture) 
Select dt_Input.Clone.Rows.Add({row(0).ToString, dateCol.ToString("dd-MM-yyyy"), dateCol.ToString("MMM")})).CopyToDataTable

Code Explaination :

  • Filters rows with non-empty “PO Date” values.
  • Converts the “PO Date” string to a DateTime type using the specified format.
  • Formats the date to “dd-MM-yyyy” and extracts the month from it.
  • Creates a new DataTable with same structure as input and fills all the details to it

Output File :
Month.xlsx (9.8 KB)

Below is the code Zip file for your Reference :

ConvertMonth_ToText.zip (11.4 KB)

Hope it helps you

Regards,
Vikas

1 Like

@domsmgtmeet22

you can try this as below:

  1. Read Range → dtPO
  2. Add Data Column → dtPO : “Month”
  3. For Each Row in dtPO
    a. Assign → poDate = DateTime.ParseExact(row(“PO Date”).ToString(), “dd-MM-yyyy”, System.Globalization.CultureInfo.InvariantCulture)
    b. Assign → monthValue = poDate.ToString(“MMMM”)
    c. Assign → row(“Month”) = monthValue
  4. Write Range → dtPO

Okay got it… @domsmgtmeet22

Follow the below steps,
→ Use the Read range workbook activity to read the Input excel and store in a datatable called DT.
→ Then use the Assign activity and create a datatable datatype varibale called OutputDT. Then give the below LINQ Expression,

- Assign -> OutputDT = (From row In DT.AsEnumerable() 
                        Let PoDate = row("PO Date").ToString() 
                        Let Month = If(Not(String.IsNullOrEmpty(row("Month").ToString()) OrElse String.IsNullOrWhiteSpace(row("Month").ToString())), DateTime.ParseExact(PoDate, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture).ToString("MMM"), row("Month").ToString()) 
                        Select DT.Clone().Rows.Add(row("PO Name").ToString(), PoDate, Month) 
                       	          ).CopyToDataTable()

→ Then use the Write range workbook activity to write the OutputDT to the same excel sheet.

Hope it helps!!

Hi @domsmgtmeet22,

Kindly follow the steps mentioned below,

Step 1: Read the Excel File

  1. Use the Read Range Workbook activity: to read the data from the Excel sheet into a DataTable.
  • Assign the output to a variable, e.g., dt_Input.

Step 2: Use LINQ to Populate the Month Column

  1. Use the Assign activity:
  • In the Assign activity, use the following LINQ query to update the “Month” column:
dt_Input.AsEnumerable().ToList().ForEach(Sub(row) row("Month") = DateTime.ParseExact(row("PO Date").ToString(), "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture).ToString("MMM"))
  • This LINQ query goes through each row in the DataTable, converts the “PO Date” to a DateTime object, extracts the abbreviated month name (e.g., “Aug”), and populates the “Month” column.

Step 3: Write the Data Back to Excel

  1. Use the Write Range activity:
  • After processing the data, use the Write Range activity to write the updated DataTable back to the Excel sheet.

Happy automation!