Convert date time veriable into string

i have datetime veriable “LastDate” which i want to convert into this format-“Saturday, February 24th, 2024” please help

Hi @Hemant_Deshmukh

Try this:

str_Date = DateTime.Now

Output = str_Date.ToString("dddd, MMMM dd, yyyy")

str_Date is of DataType System.DateTime
Output is of DataType System.String

Regards

how to write this in this format “Saturday, February 24th, 2024”

Hi,

Please find attached xaml below, which has the solution,

datetime to string Forum.zip (2.8 KB)

If this works for you, please mark it as a solution, so others can refer it… :slight_smile:

Hi @Hemant_Deshmukh

Try this way:

str_Date = DateTime.Now

Output = str_Date.ToString("dddd, MMMM dd'\t\h', yyyy").Replace("th,", "th").Replace("st,", "st").Replace("nd,", "nd").Replace("rd,", "rd")

Regards

Thanks for reply …but its showing “02th” instead “02nd”
image

str_Date=DateTime.Now.AddDays(-7)

Hi @Hemant_Deshmukh

I think the below code will match your exact requirement:

Assign-> LastDate = DateTime.Now

Assign-> formattedDate = LastDate.ToString("dddd, MMMM dd'\t\h', yyyy")

Assign-> dayOfWeek = LastDate.ToString("dddd")

Assign-> dayOfMonth = LastDate.Day

Assign-> suffix = If(dayOfMonth >= 11 AndAlso dayOfMonth <= 13, "th", If(dayOfMonth Mod 10 = 1, "st", If(dayOfMonth Mod 10 = 2, "nd", If(dayOfMonth Mod 10 = 3, "rd", "th"))))

Assign-> FinalDate = String.Format("{0}, {1:MMMM} {2}{3}, {4}", LastDate.DayOfWeek, LastDate, LastDate.Day, suffix, LastDate.Year)

Variable DataTypes


Sequence53.xaml (10.8 KB)

Regards

1 Like

Hi @Hemant_Deshmukh

Check the above, this will meet your exact requirement. Test that and let me know
I have tested the below scenarios @Hemant_Deshmukh

If LastDate = DateTime.Now.AddDays(-6)
image

If LastDate = DateTime.Now.AddDays(-7)
image

If LastDate = DateTime.Now.AddDays(-8)
image

If LastDate = DateTime.Now.AddDays(-9)
image

Regards

1 Like

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