How to make AM|PM time format in Event post form

1. Add time format in inc/js/jquery.webForms.js file:

                    $(this).datetimepicker({
                        changeYear: true,
                        changeMonth: true,
                        timeFormat: 'hh:mm tt',
                        dateFormat: 'yy-mm-dd'
                    });

2. Modify these three functions in inc/classes/BxDolForm.php file:

 

function checkDateTime ($s)
    {
        // remove unnecessary opera's input value;
        $s = str_replace('T', ' ', $s);
        $s = str_replace('Z', ':00', $s);
        return $this->checkPreg ($s, '#^\d+\-\d+\-\d+[\sT]{1}\d+:\d+\s[AMPamp]{2}$#');
    }


 

    function _passDateTime ($s)
    {
         if (preg_match('#(\d+)\-(\d+)\-(\d+)[\sT]{1}(\d+):(\d+)(\s|)(am|pm|AM|PM|)#', $s, $m)) {
            $iDay   = $m[3];
            $iMonth = $m[2];
            $iYear  = $m[1];
            $iH = $m[4];
            $iM = $m[5];
            if (isset($m[7]) && $m[7]) { 
                $iH = date("H", strtotime("{$m[4]}:{$m[5]} {$m[7]}")); 
                $iM = date("i", strtotime("{$m[4]}:{$m[5]} {$m[7]}")); 
            }
            $iRet = mktime ($iH, $iM, 0, $iMonth, $iDay, $iYear);
            return $iRet > 0 ? $iRet : 0;
        }
        return $this->passDate ($s);
    }

 

    function displayDateTime ($i)
    {
        return date("Y-m-d h:i a", $i);
    }
 


Rules → http://www.boonex.com/terms
Quote · 19 Sep 2015

Thank you for this!

Quote · 19 Sep 2015

Yes, very much appreciated!

7.3.5 with responsive UNI
Quote · 19 Sep 2015

Alex, It works when I first create an event, but when I return to the event edit screen and click save, I get an error message for both date fields.  "date format is incorrect".  What date format setting needs to match up?

Thank you

Quote · 9 Dec 2015

Alex,

Any fix here?  This is a great modification, but the error is a problem.  The am/pm disappears when the event edit screen is reopened.  Any ideas?  Language time format settings or code?

Thank you for your help.

Quote · 11 Dec 2015

I think you need to make one more change in inc/classes/BxDolForm.php file:

    function displayDateTime ($i)
    {
        return date("Y-m-d h:i a", $i);
    }
Rules → http://www.boonex.com/terms
Quote · 14 Dec 2015

Thanks Alex.  Where's the best place to paste that code?

Quote · 14 Dec 2015

You need to change the text in bold in inc/classes/BxDolForm.php file.

Thanks Alex.  Where's the best place to paste that code?

 

Rules → http://www.boonex.com/terms
Quote · 14 Dec 2015

That's the problem.  I don't see that code in the jquery.webForms.js file.  Do you have a line number?  This is for version 7.2.

Quote · 14 Dec 2015

Sorry, my mistake, the code is in inc/classes/BxDolForm.php file. 

That's the problem.  I don't see that code in the jquery.webForms.js file.  Do you have a line number?  This is for version 7.2.

 

Rules → http://www.boonex.com/terms
Quote · 14 Dec 2015

Alex.  That did the trick!  Thank you.

Quote · 15 Dec 2015

I am having an issue. After doing all these changes, am pm shows up on the create event. Once the event is created, 24hr format is displayed in the event info time instead of am pm. 

Quote · 26 Jan 2016

 

Once the event is created, 24hr format is displayed in the event info time instead of am pm. 

You can change this, by changing format here:

Admin Panel > Settings > Languages Settings > Settings > Long Date Format (For Code) & Long Date Format (For Database)

 

Rules → http://www.boonex.com/terms
Quote · 31 Jan 2016
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.