Hot answers tagged

6

Finally I found the solution for this Error by passing the object of DateTimeZone as a parameter (notice the $date->setTimezone(new DateTimeZone($tz)); in the code bellow). It's working fine. if($date === null ) { $date = JFactory::getDate(); $tz = JFactory::getConfig()->get( 'offset' ); $date->setTimezone(new DateTimeZone($tz)); //here! $...


6

OK so I believe this to be true :) I was looking for a Joomla answer whereas I needed to use some Joomla and some php to get what I wanted. JDate works off UTC timezone by default. So you need to apply your server timezone offset (or user timezone offset) to the date first. That way, $config = JFactory::getConfig(); $offset = $config->get('offset'); ...


4

You should be able to use the following if you want to add 15 working/business days: $date = JFactory::getDate(); $newDate = new JDate($date . ' +15 Weekday'); $toFormat = $newDate->format('Y-m-d'); Today is the 24th April 2015, so $date (excluding the time), will output the following: 2015-04-24 and $toFormat will output the following: 2015-...


4

Go to Extension Manager -> Language Manager. Select Overrides. Select the Language for which you want to set an override and change the date format. Add a new override. Select the Constant option (Search for the constant DATE_FORMAT_LC2/LC3/LC4). Modify its value and save the changes. Just remove the text and type in the format you'd like. For example, if ...


4

Open the file /libraries/joomla/factory.php and search for getDate() function: public static function getDate($time = 'now', $tzOffset = null) The default value of time zone offset ($tzOffset) is null and not 0. It may be due to a mistake in Joomla documentation or it's for versions older than 2.5. In Joomla 3, $date_zero_offset = JFactory::getDate('now', ...


4

JHtml::date() will automatically use your timezone setting. JHtml::date('now', 'Y-m-d H:i:s'); See the answer here


4

Answer in the update. Just needed the correct joomla code! Okay seemed to have worked it out. $todayDate = JFactory::getDate('now', $timezoneis); $date = JFactory::getDate($itemStartDate, $timezoneis); $date2 = JHtml::date($itemStartDate , 'Y-m-d H:i:s', $timezoneis); echo "<br>database date is ".$itemStartDate; ...


3

I always compare dates with unix timestamps. In this day, there is no question about minutes or timezones. if ($expected->toUnix() < $today->toUnix()) On the other hand, if you want to only compare only the date part, you can just format the dates and compare them with the simple string comparison: if ($expected->format('Y-m-d') < $today-&...


3

By default JHtml::date() accounts for user's timezone, which, if not set, defaults to site's timezone (set in Global Configuration). Pass another argument with value null to leave the date as is. Also, because you're using a hardcoded string for format, you don't need to wrap it in JText::_(): echo JHtml::_('date', $edit, 'l F j Y g:ia', null); You should ...


3

It might be an idea to get the offset from your Global Config like so: $date = JFactory::getDate($input='now', 'UTC'); $tz = JFactory::getConfig()->getValue('config.offset'); $date->setOffset($tz); echo $date->toFormat(); To make life a little easier and have less code, I would suggest using JHtml::date echo JHtml::date($input = 'now', 'm/d/Y',...


2

Sorry that answering on so old question, but just wanted to say that there is no built-in way to make it. You should consider to create your own field type and implement the logic there.


2

Haven't used JDate for this, but the below PHP code works it for us: // Current Date $current_date = date('Y-m-d'); list ($year, $month, $day) = explode('-', $current_date); $today = new DateTime(); $today->setDate($year, $month, $day); // This Quarter $month = $month % 3 ? $month + 3 - ($month % 3) : $month; // $this_date = new DateTime(); $this_date-&...


2

I looked at the code for this. JDate::dateformat is public, which means ANY code can modify the value. I would start doing a grep/search through my source tree (and any plugins/modules/libraries) to look for assignments to it. Looking at the Time difference issue, what I think is that JFactory() is constructing the date two different ways. The first, with ...


2

$mydate = $item->displayDate; simply refers to the date string, therefore $mydate is not an object and you cannot format() it. You'll need to pass the date string through JHtmlDate like so: echo JHtml::_('date', $item->displayDate, 'j M Y');


2

The SQL that returns the most recent modified date across all your articles: SELECT `modified` FROM `#__content` GROUP BY `modified` ORDER BY `modified` DESC LIMIT 1 Then you would need to build a Joomla select query in PHP: $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select($db->quoteName(array('modified'))); $query->from($...


2

With thanks to @glenn-arkell who pointed me in the right direction, for j3.9 this works to stop Joomla writing '0000-00-00 00:00:00' into the checked_out_time field. For other fields (eg modified and any of your own datetime fields) use bind() or prepareTable() and getItem() to set empty dates from a form control to null and null dates back to zero for use ...


1

why would someone has a totaly wrong date on his system?! but to answer your question: have you tried to set the filter to server_utc? from the docs: filter (optional) is time zone to be used. There are two values; server_utc and user_utc. The first one is server time zone and the later is user time zone as configured in global configuration and user ...


1

You could create a language override for the Persian language. The Joomla documentation shows you how to do that: https://docs.joomla.org/J3.x:Language_Overrides_in_Joomla You could copy the following English language strings from /language/en-GB/en-GB.ini to your Persian language override: DATE_FORMAT_LC="l, d F Y" DATE_FORMAT_LC1="l, d F Y" ...


1

The basic issue is that sql datetime field format is this: 'YYYY-MM-DD HH:MM:SS'. You can only save a date in this format when you save a date/time value (in MySQL at least). If you have a calendar html input field (a DatePicker) and because of a language (country) you have to change the format of the date (for example to this: 'DD-MM-YYYY HH:MM:SS'), then ...


1

The functionality you're referring to has not been implemented for the Last Visit Date in the Joomla User Manager. If you open the following file and go to line 152: administrator\components\com_users\views\users\tmpl\default.php you will see the following: <?php echo JHtml::_('date', $item->lastvisitDate, 'Y-m-d H:i:s'); ?> You can create a ...


1

I cannot be too specific without knowing the exact database table structure and data, but it seems that your date values are being stored and processed as: dd [delimiter] mm [delimiter] yyyy (delimiters may logically be / or -) For instance, if you are storing the date as a VARCHAR and the string looks like 22/08/17, 30/08/17,23/11/17,30/11/17 then it is ...


1

Modifying page layout The full AMP page layout as well as all sections are implemented by wbAMP as JLayout. This means you can override any part of the output through your template overrides. Please refer to Joomla! documentation for details. wbAMP JLayouts are located in the /plugins/system/wbamp/layouts folder. If you are trying to create ...


1

I fixed it by creating JDate object $time_offset = "Australia/Sydney"; $start_time = "2015-07-31 15:03:00"; $date_end = JDate::getInstance('now', $time_offset); $date_start = new JDate($start_time); $date_start->setTimezone(new DateTimeZone($time_offset)); echo $date_end; echo $date_start;


1

Rather than trying to format using mysql, i would rather to do it in php directly using JDate. for example: // Your date from database $myStringDate = '2018-06-19 09:04:05'; // Use it in a JDate instance $date = JFactory::getDate($myStringDate); // Output using the format of your choice (see http://php.net/manual/en/function.date.php) echo $date->...


1

The joomla use in php code articles this code to show date and time: <?php echo JHtml::_( 'date', $article->displayDate, $this->escape($this->params->get('date_format', JText::_('DATE_FORMAT_LC3'))) ); ?> Joomla use string 'DATE_FORMAT_LC3' to format date and time. If your site was use language english you can change the file in: /...


1

Couldn't get the date correctly in Joomla! v.3.9.14, here's my (proven) solution: $oUser_TZ = JFactory::getUser()->getTimezone(); $aUser_tz = (array)$oUser_TZ; // almost sure this step is not that necessary $full_date = JFactory::getDate('now', $aUser_tz['timezone']); // pretty sure $oUser_tz->timezone will work // I had try to use $full_date->...


Only top voted, non community-wiki answers of a minimum length are eligible