[Tutor] Help me with this problem relating to datetime

John Fouhy john at fouhy.net
Thu Nov 16 01:38:47 CET 2006


On 16/11/06, Asrarahmed Kadri <ajkadri at googlemail.com> wrote:
> Hi Folks,
>
>
> I have got a date (as string), time (as string) , number of slots ( integer)
> and delta ( which is in seconds).
> I want to create a dictionary which has got date as the key, and the value
> should be a tuple with two elements (start_time, end_time).
>
> I will take start_time and find the end_time using delta. This pair of start
> and end times have a corresponding date. The date will be used as the key
> for the dictionary. Once the time crosses midnight, the date will change.

Which part are you having trouble with?

To convert a string into a Date or Datetime object, use
time.strptime(), and then build a Datetime from the resulting
time_tuple.
(in Python2.5, I think, the datetime module has its own strptime()
function, which short-cuts this process)

-- 
John.


More information about the Tutor mailing list