Problem with date format
#2
Posted 07 October 2011 - 08:24 AM
You should be able to define format in the field details setting. Once you created the datetime field and save there is more options on top tabs. look for "Details"...
@somartist | modules created | support me, flattr my work flattr.com
#4
Posted 07 October 2011 - 08:42 AM
No matter what you specify in the details setting. When on page editing it shows info text: "m/d/Y" , but when entering, it is only valid with something like 10-08-2011. If you use the datepicker it works, just not the way you would expect.
The output at template using echo $page->datefieldname; though it outputs as you defined in settings.
@somartist | modules created | support me, flattr my work flattr.com
#6
Posted 07 October 2011 - 09:06 AM
We recommend using 'd-m-Y' (with dashes) for European dates or 'm/d/Y' (with slashes) for US dates...
What that means is that it has to be a format that PHP's strtotime() function understands. Meaning, you'll want to use dashes rather than slashes for d-m-Y. Here are the date formats strtotime understands: http://www.php.net/m...ormats.date.php
As for the date picker populating the format Y-m-d, it does that because javascript (jQuery) and PHP don't use the same date format strings, so we have to use an ISO-standard date format for something that is automatically populated from a date picker. So we're using ISO-8601 (without time component) which is recognized in the same way by both JS and PHP. As soon as you hit save, it'll show you the date in your preferred format.
So this all works, but there are those caveats. If you guys can think of a better way for us to do it, let me know.
#7
Posted 07 October 2011 - 09:22 AM
So this makes sense, and works no matter if i enter manually with slashes or dashes.. strtotime does recognize them all.
But using jquery datepicker is not right. There's options to configure ui datepicker. SO if selecting a date it enters in the way you define it. I worked with it a few times and I see no problems with doing it. The way it is now, it populates the field with a standard date like "2011-10-09" which does work and gets transformed when saving, but would be nicer to have it populate the way you defined under input settings.
But maybe I'm getting it wrong with what's behind it in PW. Would strtotime not work when implementing this because it doesn't know which is d and wich is m? Is that the ISO format you're speaking about?
@somartist | modules created | support me, flattr my work flattr.com
#8
Posted 07 October 2011 - 09:49 AM
but would be nicer to have it populate the way you defined under input settings.
I totally agree. But the jQuery dateformats are not the same as the PHP date formats. I don't want to have to ask the user to define the date in two different formats (PHP date, and jQuery datePicker format). If these two were the same, then that would be great, but they aren't:
http://docs.jquery.c...cker.formatDate
http://www.php.net/m...nction.date.php
The only way around it that I can see is to have something to translate one input format to another, or just offering predefined date formats. I decided it would be better to give the user the most flexibility by letting them use any date format, with the compromise of having the datepicker use it's own format. Let me know if you can think of any alternate way to do it.
Note that the link I posted before was outlining formats that strtotime() can recognize for input (and there is similarity to the jQuery formats), but PHP doesn't recognize them for output (unless I've missed something), and we need the output formats to be the same. Input format doesn't matter too much since strtotime() recognizes near everything.
#9
Posted 07 October 2011 - 10:01 AM
You can display alternates, and may have a input hidden field thats used to save it using iso.
@somartist | modules created | support me, flattr my work flattr.com
#10
Posted 07 October 2011 - 10:23 AM
#11
Posted 07 October 2011 - 10:45 AM
This is exactly what's needed to solve the problem here with datepicker. You can display the date in a user defined format (visible to the user), while have a different format output to a hidden field and use only that to save it to db. I've done it myself in apps, so I see no problem with this approach.
Quoted from jquery ui doc:
"The dateFormat to be used for the altField option. This allows one date format to be shown to the user for selection purposes, while a different format is actually sent behind the scenes. For a full list of the possible formats see the formatDate function"
http://jqueryui.com/...ption-altFormat
EDIT: ah, do you mean by format, what the user defines in PW field setting like d/m/y isn't compatible with ui datepicker format?
@somartist | modules created | support me, flattr my work flattr.com
#12
Posted 07 October 2011 - 11:21 AM
ah, do you mean by format, what the user defines in PW field setting like d/m/y isn't compatible with ui datepicker format?
Exactly–that's the issue. The alternate field doesn't do us much good just because that's for sending input back to the CMS to be saved, and we have no problem with that at present. The only issue is just in getting datepicker to output the selected date in the same format it does in PHP. While there are ways to solve it, none are particularly simple, and days(s) long projects for visual tweaks to the datepicker aren't at the highest priority at this stage (though eventually will be).
#13
Posted 07 October 2011 - 07:57 PM
<?php
$replace = array(
'd'=>'dd',
'D'=>'D',
'j'=>'d',
'l'=>'DD',
'N'=>'',
'S'=>'',
'w'=>'',
'z'=>'',
'W'=>'',
'F'=>'W',
'm'=>'mm',
'M'=>'M',
'n'=>'m',
't'=>'',
'L'=>'',
'o'=>'yy',
'Y'=>'yy',
'y'=>'y',
'a'=>'',
'A'=>'',
'B'=>'',
'g'=>'',
'G'=>'',
'h'=>'',
'H'=>'',
'i'=>'',
's'=>'',
'u'=>'',
'e'=>'',
'I'=>'',
'O'=>'',
'P'=>'',
'T'=>'',
'Z'=>'',
'c'=>'',
'r'=>'',
'U'=>''
);
$str = "Y.m. l H:i:s";
$out = str_replace(array_keys($replace),$replace,$str);
$out = preg_replace("/^((?![a-zA-Z]).)+/", '', $out);
$out = preg_replace("/((?![a-zA-Z]).)+$/", '', $out);
echo "PHP to jQ UI dateformat: '$str' => '$out'<br/>";
@somartist | modules created | support me, flattr my work flattr.com
#15
Posted 31 October 2011 - 05:04 PM
@somartist | modules created | support me, flattr my work flattr.com
#17
Posted 07 November 2011 - 06:15 AM
If you add date in wrong format, after saving it says
Change: datefield
But silently keeps the old value. Also php format values (like: j.n.Y H:i) doesn't say anything for normal people (ie. non-coders), so I would leave those out.
I actually would like to see some predefined solution here. Or maybe some kind of "hybrid", like Zoho invoicing has:
#18
Posted 07 November 2011 - 09:12 AM
#19
Posted 07 November 2011 - 09:17 AM
But silently keeps the old value. Also php format values (like: j.n.Y H:i) doesn't say anything for normal people (ie. non-coders), so I would leave those out.
Tested this little bit more. It actually falls back to current date, if that is set ("If checked, this field will hold the current date when no value is entered.").
Great to know that language support has dates covered, great news!
#20
Posted 26 March 2012 - 01:12 AM
Currently it is impossible to get date picker to work with Finnish date format: d.m.Y - it messes up months and days.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users













