Get the current date, python 2.2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nano

    #1

    Get the current date, python 2.2

    Using python 2.2 what is the simplest way to get the current date value?
    I have looked in so many places. The question is often asked and the
    usual response indicates how to get the current date and time like

    now = time.localtime( )

    I want just the date, like 2007-06-15. The value will go into a
    postgresql Date type column.

    Also, if postgres field of this type is set to time.localtime( ), is the
    time portion of the date discarded, or stored 'invisibly', of will there
    be an error of some type? Just thought someone here might know.
  • Rob Williscroft

    #2
    Re: Get the current date, python 2.2

    On Fri, 15 Jun 2007 14:30:36 -0700, nano wrote:
    Using python 2.2 what is the simplest way to get the current date value?
    I have looked in so many places. The question is often asked and the
    usual response indicates how to get the current date and time like
    >
    now = time.localtime( )
    >
    I want just the date, like 2007-06-15. The value will go into a
    postgresql Date type column.
    >>import datetime
    >>d = datetime.date.t oday()
    >>d.isoformat ()
    '2007-06-15'
    >>>
    Rob.

    Comment

    • nano

      #3
      Re: Get the current date, python 2.2

      In article <KJSdnfIyZopS m-7bRVnyjwA@pipex .net>, rtw@freenet.co. uk
      says...
      On Fri, 15 Jun 2007 14:30:36 -0700, nano wrote:
      >
      Using python 2.2 what is the simplest way to get the current date value?
      I have looked in so many places. The question is often asked and the
      usual response indicates how to get the current date and time like

      now = time.localtime( )

      I want just the date, like 2007-06-15. The value will go into a
      postgresql Date type column.
      >
      >>import datetime
      >>d = datetime.date.t oday()
      >>d.isoformat ()
      '2007-06-15'
      >>>
      >
      Rob.
      >
      Thanks, I'd read that today() was only good for 2.3?

      Comment

      • Rob Williscroft

        #4
        Re: Get the current date, python 2.2

        On Fri, 15 Jun 2007 14:46:20 -0700, nano wrote:
        In article <KJSdnfIyZopS m-7bRVnyjwA@pipex .net>, rtw@freenet.co. uk
        says...
        >On Fri, 15 Jun 2007 14:30:36 -0700, nano wrote:
        >>
        Using python 2.2 what is the simplest way to get the current date
        value? I have looked in so many places. The question is often asked
        and the usual response indicates how to get the current date and time
        like
        >
        now = time.localtime( )
        >
        I want just the date, like 2007-06-15. The value will go into a
        postgresql Date type column.
        >>
        > >>import datetime
        > >>d = datetime.date.t oday()
        > >>d.isoformat ()
        > '2007-06-15'
        > >>>
        > >>>
        >Rob.
        >>
        Thanks, I'd read that today() was only good for 2.3?
        Right I missed that, though its actually the datetime module that
        is new in 2.3.

        This should do though:
        >>import time
        >>time.strftime ( "%Y-%m-%d" )
        '2007-06-15'
        >>>
        --
        Rob.

        Comment

        Working...