-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Format dd/mm/yy doesn't work #34
Comments
I've been a bit reluctant to add dd/mm/yy as a valid time format since it's not a "valid" format, but .. ok, I'll add it to the next release. Thank you for the code sample. |
I'm curious what is meant by 'dd/mm/yy ...[is] not a "valid" format'. Is this a coding issue or a convention issue? If conventional, dd/mm/yy is standard in Europe. |
The format 'dd/mm/yy' is standard in the UK and this plugin didn't work when using that format. I'm not sure about the default format in other countries. |
By "not valid" I mean that strtotime doesn't understand dd/mm/yy (see notes: "if the separator is a slash (/), then the American m/d/y is assumed"). If the requirements for running WordPress were PHP 5.3 I would have used DateTime::createFromFormat, but it's PHP 5.2.4 and hence I have to use strtotime . |
Fixed, please test the latest version here at github @BIOSTALL, I did this (to support d/m/y (i.e. a single 'd'), there are some countries using it: function update_value( $value, $post_id, $field ) {
$field = array_merge($this->defaults, $field);
if ($value != '' && $field['save_as_timestamp'] == 'true') {
if (preg_match('/^dd?\//',$field['date_format'] )) { //if start with dd/ or d/ (not supported by strtotime())
$value = str_replace('/', '-', $value);
}
$value = strtotime( $value );
}
return $value;
} |
I'm using the date format dd/mm/yy, however after saving the date either disappeared or came back in the wrong format. For example, saving 06/11/2013 would come back as 11/06/2013.
The problem is because the plugin uses the strtotime() PHP function which assumes the day and month be in a specific order. As a result I changed the update_value() function in file date_time_picker-v4.php as follows:
Otherwise, great plugin :) Thanks.
The text was updated successfully, but these errors were encountered: