Hi Niphlod,

Am building a one page Ajax app using dhtmlx and web2py as the backend
engine so for it's working excellent can share the code when done. So most
of the dhtmlx UI elements like talking in json. So I hv represented my
dates as "%d/%m/%Y" so the UI expects me to give back a date in that format
in json.

My first attempt was this:

json_rs = db(db.mytable).select(datetime.strptime(db.mytable.startDate,
'%Y-%m-%d').strftime('%d/%m/%Y')).as_json()

I was getting Value Error messages and was advised to manipulate dates
outside the query. So my second option was to do just that, I queried as a
list now, parsed through the elements and changed dates format using
strptime and then used json.dumps(listObj) to return to the dhtmlx  UI for
display. It works.

However lost a bit of web2py magic there added 6 or so extra lines of code
mostly the for loops to go through the list to achieve this.

So far dhtmlx and web2py have been working seamless with a few tweaks
though.

Seasons greetings
On 30 Dec 2013 22:09, "Niphlod" <niph...@gmail.com> wrote:

> stop right there, I see a lot of confusion going around :-P
>
> unless in sqlite, where dates are stored as strings and parsed back,
> datetimes in other engines are stored as datetimes (meaning, not strings).
> the %Y-%m-%d notation is the ISO format (i.e. a default way to represent a
> date as a string).
> What you get back using a select() is indeed a datetime object.
>
> So, what you want to change is the **representation** of that datetime
> object as a string, not the way it's stored.
>
> BTW, the IS_DATE validator attached to any Field has a default
> "represent()" function that "translates" the date into the local format,
> using T(), so e.g. if you're displaying records using SQLTABLE or
> SQLFORM.grid, or a form, those "datetimes" gets formatted (represent()ed)
> according to the specification of the '%Y-%m-%d' string in your languages
> (and the calendar widget gets translated too).
> So the question is: how are you displaying your data ? If you're not using
> web2py "facilities", you can either use strftime or the represent() itself.
>
> http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Rendering-rows-using-represent
>
> On Monday, December 30, 2013 8:27:30 PM UTC+1, software.ted wrote:
>>
>> I have noted that mysql stores its dates as "%Y-%m-%d", i would like to
>> know if the Field() or any DAL method is available to change the date to
>> "%d/%m/%Y" when doing a select?
>>
>>
>>
>> --
>> ............................................................
>> ...........................
>> Teddy Lubasi Nyambe
>> Opensource Zambia
>> Lusaka, ZAMBIA
>>
>> Cell: +260 97 7760473
>> website: http://www.opensource.org.zm
>>
>> ~/
>> Human Knowledge belongs to the world! - AntiTrust
>>
>> Man is a tool-using animal. Without tools he is nothing, with tools he is
>> all - Thomas Carlyle 1795-1881
>>
>> /~
>>
>  --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to