473,386 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 6233
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Harald Hanche-Olsen | last post by:
I'm confused. I was going to try linkchecker, and it dies with a traceback ending in File "/usr/local/lib/python2.4/calendar.py", line 32, in _localized_month _months = AttributeError:...
14
by: deko | last post by:
This runs, but does not narrow to current week. suggestions appreciated! SELECT lngEid, dtmApptDate, Subject, Appt_ID FROM qry002 WHERE (dtmApptDate BETWEEN DateAdd("d",-weekday()+2,) And...
11
by: Ken Varn | last post by:
I want to be able to determine my current line, file, and function in my C# application. I know that C++ has the __LINE__, __FUNCTION__, and __FILE___ macros for getting this, but I cannot find a...
7
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make sure the date is greater than or equal to the...
6
by: vijayk | last post by:
Hi all, I have a field which has data as YYYYMMDD, and I have to find the age of the person by substracting it from current date. can you please please advice... thanks
2
by: markryde | last post by:
Hello, I am trying to add the current date to a file name in python script like thus: import os import sys import rpm import time import datetime
0
by: Shawger Lager | last post by:
Hi, I am new to DB2 (and SQL) and I am having some problems with the current date. I am trying to make sure the date in the table review is not past the current day using a constriant. I have tried...
0
by: remya1000 | last post by:
I need to display current month,last 3months,6months and 1year records seperatly. and first i'm tring to display current month's records. and the error i received is this. Microsoft VBScript...
5
by: bruce24444 | last post by:
I have a database which assigns warranty claims to people with a main screen showing number of files assigned to each person. The number assigned shows day, week, month and year numbers so they can...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.