Date Difference in php on days? [duplicate]

I would recommend to use date->diff function, as in example below: $dStart = new DateTime(‘2012-07-26’); $dEnd = new DateTime(‘2012-08-26’); $dDiff = $dStart->diff($dEnd); echo $dDiff->format(‘%r%a’); // use for point out relation: smaller/greater see http://www.php.net/manual/en/datetime.diff.php

What is the most straightforward way to pad empty dates in sql results (on either mysql or perl end)?

When you need something like that on server side, you usually create a table which contains all possible dates between two points in time, and then left join this table with query results. Something like this: create procedure sp1(d1 date, d2 date) declare d datetime; create temporary table foo (d date not null); set d … Read more

How to calculate the difference between two dates using PHP?

I suggest to use DateTime and DateInterval objects. $date1 = new DateTime(“2007-03-24”); $date2 = new DateTime(“2009-06-26”); $interval = $date1->diff($date2); echo “difference ” . $interval->y . ” years, ” . $interval->m.” months, “.$interval->d.” days “; // shows the total amount of days (not divided into years, months and days like above) echo “difference ” . $interval->days … Read more

How to calculate “time ago” in Java?

Take a look at the PrettyTime library. It’s quite simple to use: import org.ocpsoft.prettytime.PrettyTime; PrettyTime p = new PrettyTime(); System.out.println(p.format(new Date())); // prints “moments ago” You can also pass in a locale for internationalized messages: PrettyTime p = new PrettyTime(new Locale(“fr”)); System.out.println(p.format(new Date())); // prints “à l’instant” As noted in the comments, Android has this … Read more

Difference in days between two dates in Java?

I would suggest you use the excellent Joda Time library instead of the flawed java.util.Date and friends. You could simply write import java.util.Date; import org.joda.time.DateTime; import org.joda.time.Days; Date past = new Date(110, 5, 20); // June 20th, 2010 Date today = new Date(110, 6, 24); // July 24th int days = Days.daysBetween(new DateTime(past), new DateTime(today)).getDays(); … Read more