Email Parser

Extract data from incoming emails and automate your workflow

MENUMENU

How to correct the email date/time to the required time zone



 

Email Parser automatically uses your local time (as set in Windows) to give a value to the fields DateTimeSent and DateTimeProcessed. But you may need to have these times adjusted to UTC+0 time or another time zone. For this you need to use a small script:

 

As you can see in the screenshot above, the script takes the value of DateTimeSent, available in any email by default, and adds or subtracts the number of hours set in the hours_difference variable. Here is the full script, you only need to copy/paste it in a new field inside a Parser:

using System;
using System.Text;
using System.IO;
using System.Collections.Generic;
using EmailParserBackend.ScriptingInterface;
 
public class MyScriptBasedEmailParser : ScriptBasedParser
{
    public override List<string> ExtractTextFrom(string input_text)
    {
        // 
        // Enter a positive or negative amount
        // of hours to do the time zone correction
        //
        int hours_difference = -2;
    
        List<string> captured_values = new List<string>();
 
        try
        {
            DateTime date_time_sent = DateTime.Parse(input_text);
            captured_values.Add((date_time_sent + TimeSpan.FromHours(hours_difference)).ToString());
        }
        catch(Exception ex)
        {
             captured_values.Add("Error. "+ex.Message);
        }
        return (captured_values);
    }
}