Storing date format in dd-mm-yyyy in database

699 views
Skip to first unread message

Rohit

unread,
Oct 11, 2011, 8:33:48 PM10/11/11
to web...@googlegroups.com
I am developing an online booking application where
I am storing the date using the date type of
web2py which stores the date in yyyy-mm-dd format.
I need to store the data in dd-mm-yyyy format in
the datastore.

For this I tried to use this :
date.requires = IS_DATE(format=T('%d-%m-%Y')

Though it takes the date in dd-mm-yyyy format
it does not store in the dd-mm-yyyy format.It still
stores in yyyy-mm-dd format

Please provide suggestion

Thanks

Ovidio Marinho

unread,
Oct 11, 2011, 9:16:40 PM10/11/11
to web...@googlegroups.com

      in db 

    Field('start_time','datetime',requires=IS_DATETIME(str(T('%Y-%m-%d %H:%M:%S')))),
    Field('stop_time','datetime',requires=IS_DATETIME(str(T('%Y-%m-%d %H:%M:%S')))),


   db.task.start_time.represent = lambda v: v.strftime('%d/%m/%Y')
   db.task.stop_time.represent = lambda v: v.strftime('%d/%m/%Y')

is this

in view:


<td>{{=task.start_time.date().strftime('%d-%m-%Y')}}</td>
<td>{{=task.stop_time.date().strftime('%d-%m-%Y')}}</td>

ok?



       Ovidio Marinho Falcao Neto
             ovid...@gmail.com
               83   8826 9088 - Oi
             83   9334 0266 - Claro
                   Paraiba-Brasil



2011/10/11 Rohit <rohit...@gmail.com>

Vinicius Assef

unread,
Oct 11, 2011, 10:06:56 PM10/11/11
to web...@googlegroups.com
Clarifying,
date fields are stored in internal format and they are optimized for that.

You can customize representation format, not stored format. It was
what Ovidio showed you.

--
Vinicius Assef.

Rohit

unread,
Oct 12, 2011, 10:52:07 PM10/12/11
to web...@googlegroups.com

Vinicius Assef <viniciusban@...> writes:

>
> Clarifying,
> date fields are stored in internal format and they are optimized for that.
>
> You can customize representation format, not stored format. It was
> what Ovidio showed you.
>
> --
> Vinicius Assef.
>

> On Tue, Oct 11, 2011 at 10:16 PM, Ovidio Marinho <ovidioccg@...> wrote:
> >
> >       in db
> >     Field('start_time','datetime',requires=IS_DATETIME(str(T('%Y-%m-%d
> > %H:%M:%S')))),
> >     Field('stop_time','datetime',requires=IS_DATETIME(str(T('%Y-%m-%d
> > %H:%M:%S')))),
> >
> >    db.task.start_time.represent = lambda v: v.strftime('%d/%m/%Y')
> >    db.task.stop_time.represent = lambda v: v.strftime('%d/%m/%Y')
> > is this
> > in view:
> >
> > <td>{{=task.start_time.date().strftime('%d-%m-%Y')}}</td>
> > <td>{{=task.stop_time.date().strftime('%d-%m-%Y')}}</td>
> > ok?
> >
> >
> >        Ovidio Marinho Falcao Neto

> >              ovidioccg@...


> >                83   8826 9088 - Oi
> >              83   9334 0266 - Claro
> >                    Paraiba-Brasil
> >
> >
> >

> > 2011/10/11 Rohit <rohit.bayar@...>


> >>
> >> I am developing an online booking application where
> >> I am storing the date  using the date type of
> >> web2py which stores the date in yyyy-mm-dd format.
> >> I need to store the data in dd-mm-yyyy format in
> >> the datastore.
> >>
> >> For this I tried to use this :
> >> date.requires = IS_DATE(format=T('%d-%m-%Y')
> >>
> >> Though it takes the date in dd-mm-yyyy format
> >> it does not store in the dd-mm-yyyy format.It still
> >> stores in yyyy-mm-dd format
> >>
> >> Please provide suggestion
> >>
> >> Thanks
> >>
> >
> >
>
>

So in my application, say I will store date in
yyyy-mm-dd format and I need to
retrieve the date at several pages in my application
and I want to display the
date in dd-mm-yyyy, then
one option would be to use the strftime() method
in the view wherever I
display the date.
Because I retrieve the date at several pages
in the application storing date
in dd-mm-yyyy in database would have been
much easier for me.
Since its not possible.Is there any other easier solution to achieve it.

Rohit

pbreit

unread,
Oct 13, 2011, 1:59:40 AM10/13/11
to web...@googlegroups.com
It's still generally better to store the date in a standard format and re-arrange it for display purposes. There is a good chance you will thank yourself later for doing it this way.
Reply all
Reply to author
Forward
0 new messages