tags:

views:

1171

answers:

1

I have two dates (parsed using str2time). How can I tell if one is after the other?

+11  A: 

str2time returns a "unix time", ie the number of seconds after 1 Jan 1970. So you have two integers, and you can compare them like you compare any other integers.

Paul Tomblin
But due to the way time works, you can't subtract one from the other to get the time difference between them. Leap seconds.You should really use DateTime if you care about corectness.
jrockway
Seconding jrockway's advice - basic comparisons, fine, but don't try to implement date math yourself; there's all sorts of oddness that needs to be taken into account, and that's a wheel that needn't be re-implemented.
David Precious
True enough, but I've never needed to care about the difference between two dates to the precision that a leap second would make a difference.
Paul Tomblin