The Date helper provides functions useful for working with dates and times. These are general functions that any application or website might find useful.)

Loading the Helper

	$date = Loader::helper(‘date’);

Methods

$r = $date->getLocalDateTime($systemDateTime = ‘now’, $mask = null)

Returns a date/time while checking a logged-in user’s timezone (if user timezones are enabled.)

Arguments

  • $systemDateTime - Will typically be “now”. This is passed to the PHP DateTime class. Other examples could be any sort of human-readable date.
  • $mask - null. This is the return format of the date, as specified by the date() function.
print $date->getLocalDateTime();
print $date->getLocalDateTime(‘now’, ‘F d, Y’);

$r = $date->getSystemDateTime($userDateTime = now’, $mask = null)

Converts a user entered datetime to the system datetime. Returns a date string.

array $timezones = $date->getTimezones();

Gets a list of all timezones available.

string $timeRemaining = $date->timeSince($postTime, $precise = 0)

Returns a date string in a specific format, useful for a newsfeed, since a particular $postTime. If $precise == 1, the returns are more precise.

	$r = $date->timeSince($dateOfMyPost, 1);
	print $r; // “2 days, 1 hour”

Recent Discussions on this Topic

timesince() difficulties

timeSince() doesn't appear to be working for me. What should be something around 30 minutes comes back as 12/31/1969. Essentially, [code] $myDate = time(); //