3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // Selection of creation dates taken via twitter feed $dates = array( "Wed Sep 09 14:22:40 +0000 2015", "Wed Sep 09 18:25:05 +0000 2015", "Wed Sep 09 18:25:37 +0000 2015", "Wed Sep 09 18:29:01 +0000 2015", "Wed Sep 09 18:30:27 +0000 2015", "Wed Sep 09 18:34:51 +0000 2015", "Fri Sep 11 09:01:34 +0000 2015", "Fri Sep 11 09:02:16 +0000 2015", "Fri Sep 11 09:10:30 +0000 2015", "Fri Sep 11 23:04:33 +0000 2015", "Sat Sep 12 14:41:28 +0000 2015", "Sat Sep 12 14:43:43 +0000 2015", "Sat Sep 12 15:17:38 +0000 2015", "Mon Sep 14 11:04:54 +0000 2015", "Mon Sep 14 15:59:31 +0000 2015", "Mon Sep 14 16:35:01 +0000 2015", "Mon Sep 14 18:27:55 +0000 2015", "Mon Sep 14 23:49:10 +0000 2015", "Tue Sep 15 12:39:35 +0000 2015", "Tue Sep 15 19:09:31 +0000 2015" ); // Create a date for 1 week ago. $now = new DateTime(); $purgeUntil = $now->sub(new DateInterval('P1W')); // Iterate through all, create a DateTime instance and do comparison foreach( $dates as $date ){ $tweetDate = new DateTime($date); echo ($tweetDate < $purgeUntil) ? "Purge" : "Skip"; }
Output for 5.3.18 - 5.4.45, 5.6.28, 7.0.20 - 7.2.0
SkipSkipSkipSkipSkipSkipSkipSkipSkipSkipSkipSkipSkipSkipSkipSkipSkipSkipSkipSkip
Output for 5.5.24 - 5.6.21, 7.0.0 - 7.0.6
PurgePurgePurgePurgePurgePurgePurgePurgePurgePurgePurgePurgePurgePurgePurgePurgePurgePurgePurgePurge