Ajith209
(Ajith209)
January 10, 2024, 2:07pm
1
Hi Team,
Date parsing is causing an issue due to the server date format being MM/dd/yyyy.
I have an input date format that could come in dd/MM/yyyy or MM/dd/yyyy. I need to identify month based on this. But since the server format is MM/dd/yyyy wrong month is being picked. in essence. whether it comes as 03-01-2024 or 01-03-2024 i need to fetch the month as january.
You can use the DateTime.ParseExact method to parse the input date based on the expected formats and then extract the month. Here’s an example:
Assign activity:
InputDate = “03-01-2024” // or “01-03-2024”, or any other date in dd/MM/yyyy or MM/dd/yyyy format
Assign activity:
IsDateFormat1 = True // Set to True if the input date is in dd/MM/yyyy format, False if it’s in MM/dd/yyyy format
Assign activity:
DateFormat1 = If(IsDateFormat1, “dd-MM-yyyy”, “MM-dd-yyyy”)
Assign activity:
DateFormat2 = If(IsDateFormat1, “MM-dd-yyyy”, “dd-MM-yyyy”)
Assign activity:
ParsedDate = DateTime.ParseExact(InputDate, {DateFormat1, DateFormat2}, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None)
Assign activity:
MonthName = ParsedDate.ToString(“MMMM”)
Ajith209
(Ajith209)
January 10, 2024, 2:24pm
3
How do we identify which is month here. as both 01 and 03 will come true as month in this code
Try this instead, I’m hopeful that it will work:
Assign activity:
InputDate = “03-01-2024” // or “01-03-2024”, or any other date in dd/MM/yyyy or MM/dd/yyyy format
Assign activity:
ParsedDate1 = DateTime.ParseExact(InputDate, “dd-MM-yyyy”, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None)
Assign activity:
ParsedDate2 = DateTime.ParseExact(InputDate, “MM-dd-yyyy”, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None)
Assign activity:
MonthName = If(ParsedDate1.Month = ParsedDate2.Month, ParsedDate1.ToString(“MMMM”), “Ambiguous date”)
Ajith209
(Ajith209)
January 10, 2024, 3:53pm
6
Hi Ambiguous date is coming true in both scenarios
Check the attached flow, it extracts January in both cases. However, it will work only if the dates of the current month
Main.xaml (9.4 KB)