How to convert one data format to another data format

Bot read mail received date . I received the below data format
Mon, 13 Sep 2021 09:39:25 +0000
I need to convert the above date format to 13-Sep-2021 09:39 (like this)

I tried with below code
Convert.ToDateTime(Receiveddate).Date.ToString(“dd-MMM-yyyy hh:mm”)

But time is not coming properly.

Hi,

Can you try the following expression?

Convert.ToDateTime(Receiveddate).ToString("dd-MMM-yyyy HH:mm")

Regards,

I received below output
13-Sep-2021 00:00

Time is not coming properely

Hi @BNK

Try to use this expression

DateTime.ParseExact(Split(ReceivedDate,"+")(0).TrimEnd,"ddd, dd MMM yyyy HH:mm:ss",System.Globalization.CultureInfo.InvariantCulture).ToString("dd-MMM-yyyy HH:mm")

image

Regards
Gokul

1 Like

Hi,
in my environment, it works and return date time considered TimeZone.

img20211005-3

For now, can you try the following? (without variable)

Convert.ToDateTime("Mon, 13 Sep 2021 09:39:25 +0000").ToString("dd-MMM-yyyy HH:mm")

Regards,

The “+0000” may be provoking the problem, we can avoid it by doing this:

Convert.ToDateTime(Receiveddate.Substring(0,Receiveddate.IndexOf("+"c))).ToString("dd-MMM-yyyy HH:mm")

image
Best,
Charbel

@Yoichi @Gokul001 @Charbel1

How to read the mail received date.
I Use below code
image
But i received below output
Mon, 13 Sep 2021 09:39:25 +0000

AM or PM not coming properly.

PM should show 21:39:25, isn’t it?

Original mail receive date

image

But i am receiving below output

Mon, 13 Sep 2021 09:39:25 +0000

Time is not coming properely

Hi,

Can you try the following?

Convert.ToDateTime("Mon, 13 Sep 2021 09:39:25 +0000").ToString("dd-MMM-yyyy hh:mm tt K")

Regards,

Hi @BNK

Try to use the below expression

DateTime.ParseExact(Split(di,"+")(0).TrimEnd,"ddd, dd MMM yyyy HH:mm:ss",System.Globalization.CultureInfo.InvariantCulture).ToString("dd-MMM-yyyy HH:mm tt")

Refer the link For Date Format:

Regards
Gokul

1 Like

It is working. but while get the date from mail is not working correctly.

Hi,

Can you share content of Receiveddate variable? And your first expression has extra Date method. So you need to remove it.

Regards,

Below code i used for get received date from mail

image

Hi,

Can you share its content using LogMessage, WriteLine or Messagebox?
And can you also show us your expression to convert it?

Regards,

I received below data as output for Received date

Mon, 13 Sep 2021 09:38:55 +0000

Hi,

Thank you for sharing. Doesn’t the following expression work correctly? Can you share its result and expression?

Convert.ToDateTime(Receiveddate).ToString("dd-MMM-yyyy hh:mm tt K")

Regards,

Above expression is working fine. but while get receive date from mail it is not working properly.

Hi,

Can you put the following activities, then share screenshot of output panel?

img20211005-6

Or if you have any error, please share it.

Regards,

image

Please check above logs.