Hello Cody Fendant,

Fellow Monks have provided you with the answer to your question. I would like to add another option here with one of my favorite modules regarding time manipulations Date::Manip.

Small sample of code with different timezone(s) and time subtraction. You can apply the time subtraction based on your time of receiving the email etc...

#!/usr/bin/perl use strict; use warnings; use Date::Manip; use feature 'say'; my $tz = new Date::Manip::TZ; my $dateLocal = ParseDate('now'); say $dateLocal; # From timeZone To timeZone my $dateTimeZone = Date_ConvTZ($dateLocal,"GMT","CST"); my $unixLocal = UnixDate($dateLocal,'%Y-%m-%d-%H-%M-%S'); say 'Local Timezone: ' . $unixLocal; my $unixTimeZone = UnixDate($dateTimeZone,'%Y-%m-%d-%H-%M-%S'); say 'Different Timezone: ' . $unixTimeZone; my $date1 = ParseDate($dateLocal); my $date2 = ParseDate($dateTimeZone); my $delta = DateCalc($date1, $date2, 1); say 'Difference between Timezones: ' . $delta; # Change Format my $str = UnixDate($dateLocal,"It is now %T on %b %e, %Y."); say $str; my $str_second = UnixDate($dateLocal,"It is now %T on %B %e, %Y."); say $str_second; my $str_decimal = UnixDate($dateLocal,"It is now decimal %T on %B %d, +%Y."); say $str_decimal; # Add more time or subtract or do what ever you want with time my $deltastr = "12 hours ago"; my $date_past = DateCalc($dateLocal,$deltastr); # say $date; my $str_past = UnixDate($date_past,"It was 12 hours ago %T on %B %d, % +Y."); say $str_past; __END__ $ perl test.pl 2017110109:11:31 Local Timezone: 2017-11-01-09-11-31 Different Timezone: 2017-11-01-17-11-31 Difference between Timezones: 0:0:0:0:8:0:0 It is now 09:11:31 on Nov 1, 2017. It is now 09:11:31 on November 1, 2017. It is now decimal 09:11:31 on November 01, 2017. It was 12 hours ago 21:11:31 on October 31, 2017.

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: Comparing DateTime objects in different timezones by thanos1983
in thread Comparing DateTime objects in different timezones by Cody Fendant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.