1

For this question I say "offsets" but I do not really mean timezones. What I am looking for is an offset of right "now" to 1 day, 1 week or 1 month and further in the past.

http://docs.joomla.org/JFactory/getDate

In the documentation it does show a timezone offset that can be an integer, which makes me thing that will work, however passing a null or false value for the first seems like it could cause an issue. I could also pass a default date object, but that seems like its taking from the benefit of using the API.

So what I want to do is kind of like follows.

$now = JFactory::getDate();
$now->minusOffset(24 HOURS);
$query->where('created >= \'$now->toMySQL()\'');

Is there an easy way to do this? Or is it best to convert a normal php date object into getDate? So far my searching has turned up nothing on it.

1 Answer 1

2

JDate just extends DateTime class, so you can use anything that available for DateTime.

something like that:

$yesterday = JFactory::getDate('now -1 day');

or use modify()

$now = JFactory::getDate();
$now->modify('-1 day');
1
  • Perfect! this really helps me understand better how the date class was built. May 27, 2014 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.