Mail Date Conversion Issue


I am reading a mail date from Gmail which is like:-


I want to convert this date as MM/dd/yyyy format.

Please give the solution.

Thanks in advance…!! @ClaytonM @palindrome @robot11 @PrankurJoshi @bagishojha

1 Like


When you use convert.tostring for your datetime variable use
Datetime variable.tostring(“MM/dd/yyyy”)
Or if you getting as string use,
Date time.parse(stringvariable).tostring(“MM/dd/yyyy”)


1 Like

You have a space between Date and time. Change it to DateTime.parse(

Also, I tested this:

You can also use .ToString(“MM/dd/yyyy”)


Thanks for replay.

Actually I am want to read mails within 24 hours only. So I want to match the current date with mail date, but it gives error.
Please see the attached workflow below:-

It gives me error:-

@ClaytonM @megharajky @robot11 @PrankurJoshi

1 Like

It is because you are forgetting the +0530 part in your formatting. But, you don’t even need to use ParseExact, since it is already in a readable date format.

so you can change it to this:
mails.Where(Function(x) DateTime.Parse(x.Headers("Date")).Date.Equals(datetime.Now.Date))


Hi @ClaytonM,

It works for me.

Can you please give suggestions for next activity.

I am using assigning activity to read Attachment name.

But unfortunately got error:-

1 Like

It’s possible that an email doesn’t have an Attachment, so you need a condition like for example an If activity that checks if it has attachments.

You can use the condition: item.Attachments.Count > 0

Also, using CType on an Attachment to change it to an Attachment type is redundant, since it is already an Attachment type. So you should be to just use item.Attachments.FirstOrDefault.Name

Hope that helps.



It works for me.

Thank you @ClaytonM

1 Like

Hi @ClaytonM.

In my case there are five mails which I receive on current date. Among them two mails are having attachments, Bot successfully reads the two attachment name and at the end it gives me a error:- String is not recognized as a valid DateTime. (In For Each Activity)

1 Like

I suggest you output the date string for each mail using Write Line, so you know what string it is for the mails that failed. This will help identify what the issue is.

1 Like

Can u pls upload ur workflow or screenshot?

1 Like

HI @syedabidraza @ClaytonM

Please see my workflow:-

Main.xaml (12.1 KB)

1 Like

Please convert your string to date time

For e.g: convert.datetime(yourstring).tostring(“MM/did/yyyy”)

1 Like

Hi @bagishojha

I am using,

todaymail = mails.Where(Function(x) DateTime.Parse(x.Headers(“Date”)).Date.Equals(DateTime.Now.Date))

for reading only 24 hours mails.

How can I convert here?

1 Like

DateTime.Parse() is the same as CDate() and Convert.ToDate(), so what you have will work.

but, the problem is when x.Headers(“Date”) does not equal a date for some reason, which is why I had suggested that you output the datestring for each email so you can see if one of the date strings are not actually a date.

Quick answer would be to just add a condition in your code with IsDate() to verify each string is a date time value.
todaymail = mails.Where(Function(x) If(IsDate(x.Headers("Date")), DateTime.Parse(x.Headers(“Date”)).Date.Equals(DateTime.Now.Date), False) )



Thanks for Solution. @ClaytonM

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