Difference between revisions of "Calendar form field type"
From Joomla! Documentation
(Created page with "it seems like the 'format' uses the one from strftime, not date. Maybe it would be best to indeed change to date format anyway, but as it is, the documentation points to the wron...") |
(→Work around for MM-DD-YYYY: new section) |
||
Line 1: | Line 1: | ||
it seems like the 'format' uses the one from strftime, not date. Maybe it would be best to indeed change to date format anyway, but as it is, the documentation points to the wrong information | it seems like the 'format' uses the one from strftime, not date. Maybe it would be best to indeed change to date format anyway, but as it is, the documentation points to the wrong information | ||
+ | |||
+ | == Work around for MM-DD-YYYY == | ||
+ | |||
+ | If you set the format to "%m-%d-%Y" the calendar formats dates correctly. | ||
+ | However, if you specify default="NOW" a parse error is thrown like: | ||
+ | |||
+ | DateTime::__construct() [datetime.--construct]: Failed to parse time string (11-13-2012) at position 0 (1): Unexpected character | ||
+ | |||
+ | This seems to be because $this->value must be in dd-mm-yyyy format. | ||
+ | |||
+ | If you need to have MM-DD-YYYY format AND set the default date create a new calendar type and add: | ||
+ | |||
+ | if($format == "%m-%d-%Y"){ | ||
+ | //put value in dd-mm-yyyy | ||
+ | $tmp = explode("-", $this->value); | ||
+ | |||
+ | if($tmp){ | ||
+ | $this->value = $tmp[1]."-".$tmp[0]."-".$tmp[2]; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | Note: Have not test when using filter. |
Revision as of 21:02, 13 November 2012
it seems like the 'format' uses the one from strftime, not date. Maybe it would be best to indeed change to date format anyway, but as it is, the documentation points to the wrong information
Work around for MM-DD-YYYY[edit]
If you set the format to "%m-%d-%Y" the calendar formats dates correctly. However, if you specify default="NOW" a parse error is thrown like:
DateTime::__construct() [datetime.--construct]: Failed to parse time string (11-13-2012) at position 0 (1): Unexpected character
This seems to be because $this->value must be in dd-mm-yyyy format.
If you need to have MM-DD-YYYY format AND set the default date create a new calendar type and add:
if($format == "%m-%d-%Y"){
//put value in dd-mm-yyyy $tmp = explode("-", $this->value); if($tmp){ $this->value = $tmp[1]."-".$tmp[0]."-".$tmp[2]; }
}
Note: Have not test when using filter.