Get time difference between now and a DateTime field

  "SELECT SomeField, TIMESTAMPDIFF(MINUTE, MyDateTimeField, now()) as MinsSinceMyDateTimeField FROM..."
  //MinsSinceMyDateTimeField = now() - the DateTime field MyDateTimeField

Argument can be:

  • MICROSECOND
  • SECOND
  • MINUTE
  • HOUR
  • DAY
  • WEEK
  • MONTH
  • QUARTER
  • YEAR
If DateTime value is Null?

You will get a Null value returned from TIMESTAMPDIFF

  if ( (is_null($MinsSinceMyDateTimeField)) || ($MinsSinceMyDateTimeField > 10) )
  {
  }

Specifying Returned Date Format

$sql = "SELECT *,
		DATE_FORMAT(start_date, '%d/%m/%Y') AS date_start,
		DATE_FORMAT(end_date, '%d/%m/%Y') AS date_end
	FROM project_profile WHERE project_id = $project_id";
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published.