Format multiple date-Time

Hey UiPath Community,
I have a question regarding Date Time
So the question is : I have multiple Date formats in my excel like dd/mm/yy ; dd-mm-yy ; dd-MMMM-yyyy and so on
So i want to convert all of those formats into a single format

How can i do it

@Goku

Assign Activity:
dtOutput = (From row In dtInput.AsEnumerable()
Let dateStr = row(“DateColumn”).ToString()
Let parsedDate = DateTime.ParseExact(dateStr, {“dd/MM/yy”, “dd-MM-yy”, “dd-MMMM-yyyy”}, CultureInfo.InvariantCulture, DateTimeStyles.None)
Select dtOutput.Rows.Add(parsedDate.ToString(“dd/MM/yyyy”))).CopyToDataTable()

Hi @Goku ,
I think you can
use read range to get data table
use for each row in data table with if check format
In this case, we will have a way to change it accordingly
Regards,
LNV

Hi @Goku
Use format cells activity
Set format
Under category select custom
Format mention as you need
Input
image
Output
image

Hope it helps!!

Hi @Goku

  1. Use Assign activity and use below syntax:
strinput= CurrentRow("your Column name").ToString  (Datatype: System.String)
  1. Use assign activity and use below syntax:
arr_input= {"dd/MM/yy","dd-MM-yy","dd-MMM-yyyy"}     (DataType: Array(String))
  1. Use assign Acitivty:
var_DateTime= DateTime.ParseExact(str_Input.ToString, arr_Input, System.Globalization.CultureInfo.InvariantCulture)     (Datatype: System.Datetime)
  1. Print it wherever you want to print using below condition:
var_DateTime.ToString("dd/MM/yyyy")

Hope it works!!

1 Like

Hi @Goku

Use read range activity to read the data into datatable to dateList

(From date In dateList 
Let parsedDate = DateTime.ParseExact(date, {"dd/MM/yy", "dd-MM-yy", "dd-MMMM-yyyy"}, CultureInfo.InvariantCulture, DateTimeStyles.None)
Let formattedDate = parsedDate.ToString("yyyy-MM-dd")
Select formattedDate).ToList()

Replace your required format in “yyyy-MM-dd”

@Goku

If you find the solution please do mark as solution to close the loop.

Regards

Hello I have implemented the solution. I have formatted the date using DateTime.ParseExact method to format the desired format. Then store these formats in a list. Finally using while loop write the dates in each cell.
Please check it once it should be helpful .

image
image
image
image

hey @shravan.prajapati ,
Can you send your Xaml file such that i refer it and try implementing with my data

Yeah Sure. Please find the xaml file below.

Formate multiple date format.xaml (14.1 KB)

Hi @Goku - Please check the below one. I guess it makes your work easier

Hey @shravan.prajapati ,
i got below error

Hi,

This code will not work for the date format like 08.08.2023. If you want to add this then please add a if activity to validate this date and do the necessary format.

Hi ,

I have added if condition and now the code is working fine . so please try this below xaml.

Formate multiple date format.xaml (16.0 KB)

@Goku You can simply try this linq query in assign activity.

Hey @Goku ,

You can assign all the formats into an array
for eg: dateFormatsArray = {“dd/MM/yy”, “dd-MM-yy”, “dd-MMMM-yyyy”,and so on}

Loop through the DataTable: Use a “For Each Row” activity in UiPath to loop through each row in the DataTable.
Convert the dates: Inside the loop, you can use the “DateTime.ParseExact” method to convert each date to a common format.

Hope it helps you

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.