[Tutor] date matching with python and sqlite3

Righard/Riku van Roy pluijzer at gmail.com
Sat Sep 1 13:46:38 CEST 2007


I sorry, maybe I am stupid at the moment but I cannot follow your
question,....

1) User can select a date, or a range of dates.

2) At the moment you are only able to let the user select a date that
has entered the database today.

3) A value from a table called duratation will be returned for the
selected date?

4) It will only work if the date is saved in this? "2007-09-01", way.,
What other way can the date be saved?

5) You want to now how you can improve your program?

Can you give some more info please, again sorry if others understeand it
perfectly,
Righard


Op za, 01-09-2007 te 01:55 -0400, schreef Che M:
> I'm trying to allow users to select data from an sqlite database using 
> Python by choosing either a date or a range of dates.  I'm stuck at just 
> allowing the to select data that entered the database "today" and return 
> values from a column called duration.  I have this mess at the moment:
> 
> #assume they have already chosen this self.datechoice to be today
> 
> if self.datechoice == "today":
>     todaystring = str(datetime.datetime.today())
>     today = todaystring[0:10]
>     cur.execute('SELECT duration FROM datatable WHERE date =' + '"' + today 
> + '"')
> 
> The 3rd line is a way to take just the first part 10 chars of the 
> datetime.today string, so
> instead of 2007-09-01it would be just "2007-09-01", since I just 
> want
> to match it to today, not a particular time during today.  But this only 
> works if the
> dates have been saved that way--typically they are saved with the time as 
> well, so
> this method is not good and obviously not the right way to do it.
> 
> I can tell I am going about this totally wrongly and that I should be able 
> to use either
> the Python datetime functions or SQLite's date functions much better, so any 
> insight
> would be appreciated.   Thank you.
> 
> _________________________________________________________________
> A place for moms to take a break! 
> http://www.reallivemoms.com?ocid=TXT_TAGHM&loc=us
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list