datetime « date « Python Data Type Q&A

Home
Python Data Type Q&A
1.array
2.date
3.dictionary
4.Format
5.integer
6.List
7.numpy
8.regex
9.string
10.tuple
Python Data Type Q&A » date » datetime 

1. Python Date Comparisons    stackoverflow.com

I would like to find out if a particular python datetime object is older than X hours or minutes. I am trying to do something similar to:

if (datetime.now() - ...

2. Why can't I subclass datetime.date?    stackoverflow.com

Why doesn't the following work (Python 2.5.2)?

>>> import datetime
>>> class D(datetime.date):
        def __init__(self, year):
           ...

3. Generate a random date between two other dates    stackoverflow.com

How would I generate a random date that has to be between two other given dates? The functions signature should something like this-

randomDate("1/1/2008 1:30 PM", "1/1/2009 4:50 AM", 0.34)
   ...

4. How can I perform divison on a datetime.timedelta in python?    stackoverflow.com

I'd like to be able to do the following:

num_intervals = (cur_date - previous_date) / interval_length
or
print (datetime.now() - (datetime.now() - timedelta(days=5))) 
      / timedelta(hours=12)
# won't run, would ...

5. What is the easiest way to handle dates/times in Python?    stackoverflow.com

My use case is that I'm just making a website that I want people all over the world to be able to use, and I want to be able to say ...

6. Creating DateTime from user inputted date    stackoverflow.com

I'm pretty new to Python and App Engine, but what I'm trying to do is store a model which contains a DateProperty, and that DateProperty is populated with a Date entered ...

7. Handling international dates in python    stackoverflow.com

I have a date that is either formatted in German for e.g,

2. Okt. 2009
and also perhaps as
2. Oct. 2009
How do I parse this into an ISO datetime (or python ...

8. Age from birthdate in python    stackoverflow.com

How can I find an age in python from today's date and a persons birthdate? The birthdate is a from a DateField in a Django model.

9. Python dealing with dates and times    stackoverflow.com

I'm looking for a solution to the following: Given today's date, figure out what month was before. So 2 should return for today, since it is currently March, the third month of ...

10. python date difference in minutes    stackoverflow.com

How to calculate the difference in time in minutes for the following timestamp in python

  2010-01-01 17:31:22
 2010-01-03 17:31:22

11. Python human readable date difference    stackoverflow.com

I have given date strings like these:

Mon Jun 28 10:51:07 2010
Fri Jun 18 10:18:43 2010
Wed Dec 15 09:18:43 2010
What is a handy python way to calculate the difference in days? Assuming ...

12. Date calculations in Python    stackoverflow.com

I am relatively new to Python, and I am experimenting with writing the following date calc functions

  • find the date that is/was Monday for a specified datetime
  • find the first non-weekend day of ...

13. Setting the system date in Python (on Windows)    stackoverflow.com

There appears to be many packages for getting/formatting the current date, or finding out the date n time intervals from now. But I must be overlooking the existence of a simple ...

14. Get the current date as the default argument for a method    stackoverflow.com

I've got a method:

def do_something(year=?, month=?):
    pass
I want the year and month arguments to be optional but I want their default to equal the current year and month. ...

15. python date interval intersection    stackoverflow.com

As a matter of general interest I'm wondering if there's a more elegant/efficient way to do this. I have a function that compares two start/end tuples of dates returning true if ...

16. DateTime Python    stackoverflow.com

How to convert "12/17/2010 4:12:12 PM" to a datetime object? For eg, If it was like "2007-03-04T21:08:12Z", I would have done

dd =datetime.strptime( "2007-03-04T21:08:12Z", "%Y-%m-%dT%H:%M:%SZ" )
but for time with AM/PM is there any ...

17. Are there standard rules and practices for Date serialization between two languages or frameworks?    stackoverflow.com

Seems simple but I just don't know. I'm interested in serializing a date to a string or integer and sending it from Objective-C to Python, and I want to know if there's ...

18. Python: The opposite of `datetime.date.isocalendar()`    stackoverflow.com

The datetime module provides a method date.isocalendar that, given a date, returns it in the format ([year], [week], [weekday]). How do I go backwards? Given a ([year], [week], [weekday]) tuple, how ...

19. Dates in python.....need help please!    stackoverflow.com

ok so this is probably really simple but i have never used the datetime module before Basically in my code i ask the user for a date in the format dd/mm/yyyy.

currentdate = ...

20. Python isinstance() returning error with datetime.date    stackoverflow.com

I am trying to compile an old 2008 code.

import datetime

if isinstance(value, datetime.date):
But I got an error:
isinstance() arg 2 must be a class, type, or ...

21. Is it possible to subclass the immutable date class and override the __str__ method?    stackoverflow.com

I am trying to subclass the immutable date class in Python, but I also need to override the __str__ method. So far, I have the following:

from datetime import date

class Year(date):
  ...

22. Python OrderedDict ordered by date    stackoverflow.com

I am trying to use an OrderedDict (Raymond Hettingers version for pre2.7 Python) where my keys are dates. However it does not order them correctly, I imagine it may ...

23. allowing invalid dates in python datetime    stackoverflow.com

The datetime module does date validation and math which is fine when you care about reality. I need an object that holds dates generated even if they were invalid. Date time is ...

24. Why is there a date class in python    stackoverflow.com

Doesn't datetime cover all that date can do? I haven't read all the documentation, but so far I always find myself using datetime. Even in Django - datetime model fields are ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.