Date format

Archived from the Web Auction Discussion forum.

Anthony Barber — Mon Nov 05, 2007 1:22 pm

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


shannah — Mon Nov 05, 2007 3:03 pm

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


Anthony Barber — Tue Nov 06, 2007 4:45 am

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


njw — Thu Sep 11, 2008 3:58 am

but the Edit screen still displays as YYYY-MM-DD. Can this also be changed?

Many thanks

Neil


shannah — Thu Sep 11, 2008 11:42 am

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


njw — Thu Sep 11, 2008 1:15 pm

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


njw — Thu Sep 11, 2008 1:19 pm

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.


shannah — Fri Sep 12, 2008 8:52 am

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


njw — Fri Sep 12, 2008 9:07 am

so I’ll add the push value function.