3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $now = new DateTime('now'); $date = new DateTime('2015-05-01'); // Total difference in days $total_days = date_diff($now, $date)->format('%a'); // Get weeks $weeks = floor($total_days / 7); // Get days $days = $total_days % 7; echo $weeks . ' weeks and ' . $days . ' days ago';
Output for 5.3.0 - 5.3.28, 5.4.0 - 5.4.28, 5.6.28, 7.0.14 - 7.1.0
48 weeks and 2 days ago
Output for 7.0.6
52 weeks and 4 days ago
Output for 5.6.14, 7.0.5
48 weeks and 1 days ago
Output for 7.0.4
44 weeks and 6 days ago
Output for 7.0.3
46 weeks and 0 days ago
Output for 7.0.2
46 weeks and 4 days ago
Output for 7.0.1
46 weeks and 5 days ago
Output for 7.0.0
47 weeks and 1 days ago
Output for 5.6.21
52 weeks and 3 days ago
Output for 5.6.20
49 weeks and 1 days ago
Output for 5.6.19
44 weeks and 3 days ago
Output for 5.6.18
45 weeks and 3 days ago
Output for 5.6.17
46 weeks and 1 days ago
Output for 5.6.16
47 weeks and 2 days ago
Output for 5.6.15
47 weeks and 3 days ago
Output for 5.6.13
50 weeks and 0 days ago
Output for 5.6.12
50 weeks and 4 days ago
Output for 5.6.11
51 weeks and 1 days ago
Output for 5.6.10
51 weeks and 3 days ago
Output for 5.6.9
51 weeks and 5 days ago
Output for 5.6.8
52 weeks and 0 days ago
Output for 5.6.7
55 weeks and 5 days ago
Output for 5.5.35
55 weeks and 2 days ago
Output for 5.5.34
49 weeks and 2 days ago
Output for 5.5.33
44 weeks and 4 days ago
Output for 5.5.32
45 weeks and 6 days ago
Output for 5.5.31
46 weeks and 2 days ago
Output for 5.5.30
48 weeks and 0 days ago
Output for 5.5.29
50 weeks and 1 days ago
Output for 5.5.28
50 weeks and 5 days ago
Output for 5.5.27
51 weeks and 0 days ago
Output for 5.5.26
51 weeks and 4 days ago
Output for 5.5.25
51 weeks and 6 days ago
Output for 5.5.24
55 weeks and 3 days ago
Output for 5.4.39 - 5.4.45
18 weeks and 0 days ago
Output for 5.4.34 - 5.4.38
8 weeks and 2 days ago
Output for 5.3.29, 5.4.29 - 5.4.32
32 weeks and 6 days ago
Output for 5.2.0 - 5.2.17
Fatal error: Call to undefined function date_diff() in /in/V3Y8n on line 7
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/V3Y8n on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/V3Y8n on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_OBJECT_OPERATOR in /in/V3Y8n on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/V3Y8n on line 7
Process exited with code 255.