How to fetch Email Received Time From Outlook

Hi,

i want to fetch the Email Received Time From Outlook.Can anyone help me with the code snippet please.

Thanks

mailVar.Headers(“Date”)

Thanks

1 Like

@hasib08 : That will give Date right.i want only Time Ex:9:28 AM

Thanks

@avinashy - mail.Headers(“Date”) - will return complete datetime details…
you can extract only time from the variable like

out_time = Datetime.ParseExact(mail.Headers(“Date”).ToString,“HH:mm:ss tt”,System.Globalization.CultureInfo.InvariantCulture)

1 Like

You can use regex also

System.Text.RegularExpressions.Regex.Matches(VAR_Name.Headers(“Date”),"\d{2}:\d{2}:\d{2}")(0).ToString

@GBK: its not working,can you help with some other alternative.

Thanks

@hasib08 : i need only recived email time ex: 09:10 AM

@avinashy -
i just tried -
Header Date - Date : Tue, 21 Apr 2020 10:14:47 +0400
Code : DateTime.Parse(mail.Headers(“Date”)).ToString(“hh:mm:ss tt”)
Output : 10:14:47 AM

pls check and let s know! cheers!

1 Like

DateTime.Parse(mail.Headers(“Date”)).ToString(“hh:mm:ss tt”)

mail.Headers(“Date”) - is a formatted date time in string type
DateTime.Parse - to parse the string to date time and ToString(“hh:mm:ss tt”) is specifying my return results string ( from entire datetime).

@GBK:its working fine but it is diaplying in 24 hours format,how to get it in 12 hours format inclugin AM or PM

“hh:mm:ss tt” is to get time in 12 hours format (AM/ PM)
pls share the output…

@GBK : Email Recived time is 04:04 PM.

From the code the out put recived is : 16:03:55 PM. Can we convert this into 12 hour format ?

Thanks

pls check - keep the ToString(“hhmmss tt”) not (“HH:mm:ss tt”)

or try to print both -
DateTime.Parse(mail.Headers(“Date”)).ToString(“hh:mm:ss tt”) - 12 hr format
DateTime.Parse(mail.Headers(“Date”)).ToString(“HH:mm:ss tt”) - 24 hr format

1 Like