How to compare date/times in different timezones?

3 replies
I have 2 date/time strings that I need to compare to see if they are the same date / not. One is "Fri, 26 Aug 2011 14:34:55 GMT" and the other is "Sat, 27 Aug 2011 07:03:02 +1000".

I guess it's a 2-step process:
1) Convert them both to the same timezone, and then
2) Compare the date component of the date/time to see if they're the same date.

I've been searching around and am now totally bewildered and baffled by the various date & time modules available. I have tried a few and can't work out how to do this. I'm not a perl programmer, I'm an occasional dab
#compare #date or times #timezones
  • Profile picture of the author lovenot
    Originally Posted by tocktik View Post

    I have 2 date/time strings that I need to compare to see if they are the same date / not. One is "Fri, 26 Aug 2011 14:34:55 GMT" and the other is "Sat, 27 Aug 2011 07:03:02 +1000".

    I guess it's a 2-step process:
    1) Convert them both to the same timezone, and then
    2) Compare the date component of the date/time to see if they're the same date.

    I've been searching around and am now totally bewildered and baffled by the various date & time modules available. I have tried a few and can't work out how to do this. I'm not a perl programmer, I'm an occasional dab
    You are on the right track. Use the date & time modules available to compare them. Look through their documentation. There should be functions for you to use. Convert them into the same format first.
    {{ DiscussionBoard.errors[4572312].message }}
  • Profile picture of the author showmack
    Originally Posted by tocktik View Post

    I have 2 date/time strings that I need to compare to see if they are the same date / not. One is "Fri, 26 Aug 2011 14:34:55 GMT" and the other is "Sat, 27 Aug 2011 07:03:02 +1000".

    I guess it's a 2-step process:
    1) Convert them both to the same timezone, and then
    2) Compare the date component of the date/time to see if they're the same date.

    I've been searching around and am now totally bewildered and baffled by the various date & time modules available. I have tried a few and can't work out how to do this. I'm not a perl programmer, I'm an occasional dab
    You should use date functions and convert it into same timezone. Even you can try converting it into timestamp and then calculate it.
    {{ DiscussionBoard.errors[4572689].message }}
    • Profile picture of the author Tashi Mortier
      Welcome to the whole world of pain that is connected to working with time and dates in any programming language

      I really recommend that you convert the dates into a timestamp, then you can easily work with addition, subtraction and simple comparisons.

      You can then always format the timestamps into human-readable format when it's time to show them to a user.
      Signature

      Want to read my personal blog? Tashi Mortier

      {{ DiscussionBoard.errors[4577303].message }}

Trending Topics