162
votes
5answers
158k views

Converting string into datetime

Short and simple. I've got a huge list of date-times like this as strings: Jun 1 2005 1:33PM Aug 28 1999 12:00AM I'm going to be shoving these back into proper datetime fields in a database so I ...
48
votes
8answers
19k views

Iterating through a range of dates in Python

I have the following code to do this, but how can I do it better? Right now I think it's better than nested loops, but it starts to get Perl-one-linerish when you have a generator in a list ...
2
votes
4answers
5k views

Converting datetime.date to UTC timestamp in Python

I am dealing with dates in Python and I need to convert them to UTC timestamps to be used inside Javascript. The following code does not work >>> d = datetime.date(2011,01,01) >>> ...
57
votes
14answers
53k views

How do I convert local time to UTC in Python?

How do I convert a datetime string in local time to a string in UTC time? I'm sure I've done this before, but can't find it and SO will hopefully help me (and others) do that in future. ...
48
votes
5answers
19k views

How do I translate a ISO 8601 datetime string into a Python datetime object?

I'm getting a datetime string in a format like "2009-05-28T16:15:00" (this is ISO 8601, I believe) one hack-ish option seems to be to parse the string using time.strptime and passing the first 6 ...
16
votes
5answers
8k views

python time to age part 2, timezones

Following on from my previous question: http://stackoverflow.com/questions/508727/python-time-to-age I have now come across a problem regarding the timezone, turns out that its not always going to be ...
190
votes
9answers
110k views

Python datetime to Unix timestamp

I have to create an "Expires" value 5 minutes in the future, but I have to supply it in UNIX Timestamp format. I have this so far, but it seems like a hack. def expires(): '''return a UNIX style ...
107
votes
7answers
54k views

How to parse ISO formatted date in python?

I need to parse strings like "2008-09-03T20:56:35.450686Z" into python's datetime type. I have found only strptime in python 2.5 std lib, but it is not so convenient. What is the best way to do ...
82
votes
7answers
48k views

Converting unix timestamp string to readable date in Python

I have a string representing a unix timestamp (i.e. "1284101485") in Python, and I'd like to convert it to a readable date. When I use time.strftime, I get a TypeError. >>>import time ...
62
votes
2answers
30k views

How can I subtract a day from a python date?

I have a python datetime.datetime object. What is the best way to subtract one day?
19
votes
4answers
5k views

Natural/Relative days in Python

I'd like a way to show natural times for dated items in Python. Similar to how Twitter will show a message from "a moment ago", "a few minutes ago", "two hours ago", "three days ago", etc. Django 1.0 ...
4
votes
5answers
1k views

Parsing Dates and Times from Strings using python

I'm using python, and want to parsing a string like "01-Jan-1995" to datetime type of python. who can tell me how to do it? thanks.
57
votes
6answers
64k views

How to print date in a regular format in Python?

I'm only just starting out with python so I'm still pretty clueless. What I'm trying to do is to get the date from the pc and adding it to a list. This is my code: import datetime today = ...
27
votes
4answers
17k views

Python - Convert UTC datetime string to local datetime

I've never had to convert time to and from utc. Recently had a request to have my app be timezone aware, and I've been running myself in circles. Lots of information on converting local time to utc, ...
10
votes
3answers
12k views

How to convert a Date string to a DateTime object?

Ok, so I have this date: 2005-08-11T16:34:33Z I need to know if this is date is before or after datetime(2009,04,01) and I can't seem to find a method that will convert that string to something ...

1 2 3 4 5 13
15 30 50 per page