How to change the date formats

1 Like

Hi you can try this way

DateTime.ParseExact("31.05.2023","dd.MM.yyyy",System.Globalization.CultureInfo.CurrentUICulture).ToString("MMM yyyy")

@anjani_priya

follow this steps :slight_smile:

@anjani_priya

if the date is like 31 december 2021 or any other format how to change that to mm’yyyy format?

Pass them in double quotes @anjani_priya

“31.05.2023”

If that’s the case the format changes accordingly like this

dd MMMM yyyy - we need pass accordingly

stroutput = DateTime.ParseExact(strinput.ToString, “dd MMMM yyyy”, CultureInfo.InvariantCulture).ToString(“MMM’yyyy”)

I would recommend to have a view on this to know all the date format

@anjani_priya

If the formats are changing dynamically how to declare?

1 Like

Date format has to be standard and defined
we need to make it robust with stable dateformat
which is actually a good practice. Ask the user or system that generates the report to create the file with same dateformat

Or atleast if u know the possible different date format
Then you can pass it as array
It’s in above thread which I shared

Convert a String of multiple possible date formats to a Datetime variable

Say you have a date string which can be of different formats for each time it is being used like
“dd/MM/yyyy”, “MM/dd/yyyy”, “dd/yy”

Then have all these possible formats in a array variable named arr_formats

Like this

arr_formats = {“dd/MM/yyyy”, “MM/dd/yyyy”, “dd/yy”}

Then to convert that string as Datetime

var_datetime = DateTime.ParseExact(Strinput.ToString, arr_formats, System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.None)

@anjani_priya

Try this way

str= "31 december 2021"
CDate(str).AddMonths(0).AddDays(-1).toString("MMM yyyy")

@anjani_priya

Hope this Clarifies
@anjani_priya

HI @anjani_priya

you can try this it will work sure even the date formats are different also

Xaml : -
ForumDates.zip (2.4 KB)

for reference you can see input and ouput :slight_smile:

input

image

output :
image

Capture5
how to declare this month format in array?
and how to change 31st may 2022 format in mmyyyy

Hi @anjani_priya

In the array declare as MMM'yy

DateTime.ParseExact("31st may 2022","d MMMM yyyy",System.Globalization.CultureInfor.InvariantCulture).ToString("MMyyyy")

Regards

How to set jan’2023 format in an array?

How to set jan’2023 fromat?

Hi @anjani_priya

you can try out this xaml even the your input dates have st or nd or rd or th it will work anyt type of date format

Xaml : - ForumDates.zip (2.7 KB)

for reference you can see the input and out put

input : -
image

OutPut : -
image

@anjani_priya

I want month and year
In input array how to set jan’2023 format?

if you need to values to array you can try this way

arr = {"jan’2023"}

Note : arr variable type is system.string[]

image

@anjani_priya

if you need to add more to arr variable then add like this

arr = {"jan’2023",dfsdfds,sdfsdf,sdfsdf,sddfsdf}

@anjani_priya

cant we add in mmyyyy format?