0

Below is my calendar field in the form

        <field name="job_next_run_date_time" 
        type="calendar" 
        label="JSCH_JOBV_NEXT_DATE_TIME"
        description="JSCH_JOBV_NEXT_DATE_TIME_DESC"
        format="%Y-%m-%d %H:%I:%S"
        readonly="readonly"
        class="readonly" />

In database the value is stored for the field as below

2020-05-19 15:05:00

But on the screen I am rendering using the code

echo $this->form->renderField('job_next_run_date_time');

and it is displaying as below

2020-05-19 03:03:00

Why the hours part is not shown in 24 hours and minute part is changed from 05 to 03?

When changed the calendar field to a normal text field it displayed correctly as below

2020-05-19 15:05:00

On further investigation on the core Joomla library I found the below piece of code in \libraries\joomla\form\fields\calendar.php. I added an echo statement before and after.

echo $this->value;  //malai this prints 2020-05-19 15:05:00
$tz = date_default_timezone_get();
date_default_timezone_set('UTC');
$this->value = strftime($this->format, strtotime($this->value));
date_default_timezone_set($tz);
echo $this->value;  //malai this prints 2020-05-19 15:03:00

Does this gives any clue???

  • What if you try to set the field attribute: timeformat="24". I'm not sure since this should be the default value on this but maybe it can help. I do not have any clue about the altered minutes though, I've never seen that behavior at calendar field. – Zollie May 19 at 18:51
  • @Zollie no timeformat="24" dont have any effect. – Malaiselvan May 20 at 14:07
  • Do you feed the Calendar field with pre-formatted date object or you just take the date directly from the database? – Zollie May 20 at 14:19
  • @Zollie it is directly from the database. In database it is a datetime data type (mysql) – Malaiselvan May 20 at 14:21
  • I would try with creating a JDate object from the data with one or two extra lines of code like $date = new Date('2012-12-1 15:20:00'); and see if it helps or not... Link: docs.joomla.org/How_to_use_JDate – Zollie May 20 at 14:32
1

Let's try this:

Drop the format line completely from the xml definition. In its place try:

translateformat="true"
showtime="true"

and see what that gives you.

My guess here is the system is ignoring the time section of your format string because you haven't told it that the calendar field should include a time (the showtime parameter). I also think the time section of your format string is incorrect, but it's not telling you that because you haven't told it to use it, so setting translateformat to true without having a format string should test that guess without adding issues caused if I'm correct about the format string.

If making those two changes results in a better time display, feel free to test my suspicions of the format string by restoring your original format string to the definition, and either setting translateformat to false or removing it entirely (default value for this param is false, so either action will do) and see what happens.

| improve this answer | |
  • after adding these attributes, now I am seeing the correct time in 24 hours format with proper minutes and seconds as stored in the database. I tried various other combinations and nothing worked. Worked only when both are true and that is ignoring the format given. You mentioned the time section is incorrect, what do you mean by that? – Malaiselvan May 20 at 15:14
  • Lowercase i and s, as detailed here: php.net/manual/en/function.date.php If you want to test different format strings, then don't forget to set translateformat to false. – Arlen May 20 at 15:29
0

Your %I should be %i, as per the php docs you are setting a boolean value (Whether or not the date is in daylight saving time - 1 if Daylight Saving Time, 0 otherwise) in the middle of the datestring. I assume you were probably looking for lowercase i, which is minutes with leading zeros.

| improve this answer | |
  • No, %i displays nothing. The field becomes empty. – Malaiselvan May 20 at 14:10
  • @Malaiselvan try %Y-%m-%d %H:%M:%S as the format. – Grant G May 20 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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