Page 1 of 1

Date format

PostPosted: Mon Nov 05, 2007 1:22 pm
by Anthony Barber
Hi Steve,
I am making good progress but I am having to learn a lot.
I need a little bit of help here.

I also need to change the date format to d-m-y (European format).
I have read what you wrote that there are two possible methods.

function current_date__default() {
return date('d/m/Y');
}

and
%%fieldname%%__display()

I tried the function method and it did not work (I did it on all the tables where there was a date field. Had a problem in one case where there was already a Function defined on that date field).

With the second method I just don't know where to start.

When placing a bid there is a 'Bidding close time' just above the bid amount, could you please show me how to change the format on that field?
I would be most grateful.
Best regards,
Tony

PostPosted: Mon Nov 05, 2007 3:03 pm
by shannah
These methods go inside the delegate class for your table.

http://xataface.com/documentation/tutor ... te_classes

The second method is your best bet for this:

%%fieldname%%__display() means that you can implement a method in the delegate class named like %%fieldname%%__display() where %%fieldname%% is the name of the field.

e.g.
in your case it would be something like:
Code: Select all
function current_date__display(&$record){
    return date('d/m/Y', strtotime($record->strval('current_date')));
}

This would change the date display for the 'current_date' field.

-Steve

Date format

PostPosted: Tue Nov 06, 2007 4:45 am
by Anthony Barber
Hi Steve,
You know that feeling when you look at the screen and it is showing just what you had hoped for?
I just had that feeling!!
Many thanks again.
I am going to tackle the language side now.
Best regards,
Tony

Works fine for View

PostPosted: Thu Sep 11, 2008 3:58 am
by njw
but the Edit screen still displays as YYYY-MM-DD. Can this also be changed?

Many thanks

Neil

PostPosted: Thu Sep 11, 2008 11:42 am
by shannah
If you are using the calendar widget you can use the
widget:ifFormat property in the fields.ini to specify the input format.

e.g.
Code: Select all
[date_field]
    widget:ifFormat="%Y-%m-%d %I:%M %P"


Haven't tried this, but it should work.

-Steve

Sorry

PostPosted: Thu Sep 11, 2008 1:15 pm
by njw
No change - still comes out 1980-09-23 on the edit form, but as 23-Sep-1980 on the view and list forms.

(I changed the format above to %d-%M-%Y)

Neil

Further investigation

PostPosted: Thu Sep 11, 2008 1:19 pm
by njw
If you make a change with the Calendar widget it then formats ok - DD-MM-YYYY. But if you leave the form and re-enter it, the date display goes back to YYYY-MM-DD.

PostPosted: Fri Sep 12, 2008 8:52 am
by shannah
OK.. then you also need to use the fieldname__pullValue() method in your delegate class for the date field.

e.g.
Code: Select all
function datefield__pullValue(&$record, $element){
    return date('d-m-Y H:i:s', strtotime($record->strval('datefield')));
}


This is used to transform values for preparation to be used on the edit form.
There is an equivalent pushValue() field that may be necessary to transform it back, but I think that Xataface should be able to handle most date formats already so this won't be necessary.

-Steve

I get strange dates using that code

PostPosted: Fri Sep 12, 2008 9:07 am
by njw
so I'll add the push value function.