471,342 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,342 software developers and data experts.

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.
Jun 15 '07 #1
3 6148
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.today()
d.isoformat()
'2007-06-15'
>>>
Rob.
Jun 15 '07 #2
In article <KJ*********************@pipex.net>, rt*@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.today()
>>d.isoformat()
'2007-06-15'
>>>

Rob.
Thanks, I'd read that today() was only good for 2.3?
Jun 15 '07 #3
On Fri, 15 Jun 2007 14:46:20 -0700, nano wrote:
In article <KJ*********************@pipex.net>, rt*@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.today()
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.
Jun 15 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Harald Hanche-Olsen | last post: by
6 posts views Thread by vijayk | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.