klenwell information services : PythonDateTime

Revision history for PythonDateTime


Revision [3033]

Last edited on 2016-07-09 16:54:43 by KlenwellAdmin [Replaces old-style internal links with new pipe-split links.]
Additions:
For a Google App Engine project I'm working on, I have to sync the app's time zone, which on the App Engine servers is UTC, to a Google Analytic profile's (i.e. site's) time zone, which [[http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55512 | defaults to US/Pacific]].
Deletions:
For a Google App Engine project I'm working on, I have to sync the app's time zone, which on the App Engine servers is UTC, to a Google Analytic profile's (i.e. site's) time zone, which [[http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55512 defaults to US/Pacific]].


Revision [2171]

Edited on 2012-06-09 21:48:19 by KlenwellAdmin [Replaces old-style internal links with new pipe-split links.]
Additions:
>>> datetime.now().strftime("%Y%m%d%H%M%S")
'20111014140517'


Revision [2166]

Edited on 2012-06-04 15:29:27 by KlenwellAdmin [Replaces old-style internal links with new pipe-split links.]
Additions:
====Datetime to Date / Date to Datetime ====
Deletions:
====Datetime to Date====


Revision [2165]

Edited on 2012-06-04 15:28:28 by KlenwellAdmin [Replaces old-style internal links with new pipe-split links.]
Additions:
datetime.datetime(2012, 6, 4, 0, 0)
Deletions:
2012-06-04 00:00:00


Revision [2164]

Edited on 2012-06-04 15:27:57 by KlenwellAdmin [Replaces old-style internal links with new pipe-split links.]
Additions:
====Datetime to Date====
>>> from datetime import date, datetime, time
>>> today = date.today()
>>> today_as_datetime = datetime.combine(today, time())
>>> today_as_datetime
2012-06-04 00:00:00
>>> now = datetime.now()
>>> now_as_date = now.date()
>>> now_as_date
datetime.date(2012, 6, 4)


Revision [2091]

Edited on 2012-02-16 11:54:00 by KlenwellAdmin [Replaces old-style internal links with new pipe-split links.]
Additions:
>>> christmas = datetime.strptime('2010-12-25', '%Y-%m-%d')
>>> christmas
datetime.datetime(2010, 12, 25, 0, 0)
>>> christmas - timedelta(days=1)
datetime.datetime(2010, 12, 24, 0, 0)
>>> christmas.date()
datetime.date(2010, 12, 25)
>>> str(christmas.date())
'2010-12-25'
>>> datetime.strptime('2010-12-25', '%Y-%m-%d').date()
datetime.date(2010, 12, 25)
Deletions:
christmas = datetime.strptime('2010-12-25 00:00:00', '%Y-%m-%d %H:%M:%S')
christmas_eve = christmas - timedelta(days=1)
christmas_date = christmas.date()
christmas_date_str = str(christmas)


Revision [2030]

Edited on 2012-01-12 11:32:21 by KlenwellAdmin [Replaces old-style internal links with new pipe-split links.]
Additions:
====RFC 3339====
reference: http://stackoverflow.com/questions/8556398/generate-rfc-3339-timestamp-in-python
With decimal seconds stripped:
%%(python)
>>> from datetime import datetime
>>> datetime.utcnow().isoformat("T").rsplit('.')[0] + "Z"
'2012-01-12T19:36:34Z'


Revision [1942]

Edited on 2011-10-14 14:06:11 by KlenwellAdmin [Replaces old-style internal links with new pipe-split links.]
Additions:
>>> datetime.now().strftime('It is %H:%M:%S on %d %h %Y')
Deletions:
>>> datetime.today().strftime('It is %H:%M:%S on %d %h %Y')


Revision [1941]

Edited on 2011-10-14 14:01:24 by KlenwellAdmin [Replaces old-style internal links with new pipe-split links.]
Additions:
====Date to String (Date Formatting)====
>>> from datetime import date, datetime
>>> datetime.today().strftime('It is %H:%M:%S on %d %h %Y')
'It is 14:05:17 on 14 Oct 2011'
>>> date.today().strftime('Today is %Y-%m-%d')
'Today is 2011-10-14'


Revision [1553]

Edited on 2010-08-18 07:52:35 by KlenwellAdmin [Replaces old-style internal links with new pipe-split links.]
Additions:
christmas = datetime.strptime('2010-12-25 00:00:00', '%Y-%m-%d %H:%M:%S')
Deletions:
christmas = datetime.strptime('2010-12-25 00:00:00')


Revision [1552]

Edited on 2010-08-18 07:52:02 by KlenwellAdmin [Replaces old-style internal links with new pipe-split links.]
Additions:
christmas_date = christmas.date()
christmas_date_str = str(christmas)


Revision [1551]

Edited on 2010-08-18 07:31:21 by KlenwellAdmin [Replaces old-style internal links with new pipe-split links.]
Additions:
christmas = datetime.strptime('2010-12-25 00:00:00')
christmas_eve = christmas - timedelta(days=1)
Deletions:
birthday = datetime.strptime('%Y-%m-%d %H:%M:%S', '2010-05-22 08:00:00') - timedelta(years=21)


Revision [1550]

Edited on 2010-08-18 07:28:58 by KlenwellAdmin [Replaces old-style internal links with new pipe-split links.]
Additions:
====String to Date====
birthday = datetime.strptime('%Y-%m-%d %H:%M:%S', '2010-05-22 08:00:00') - timedelta(years=21)
from datetime import date, datetime, timedelta
now = datetime.now() - timedelta(days=1)
a_day_ago = now - timedelta(days=1)
a_day_from_now = now + timedelta(days=1)
http://docs.python.org/library/datetime.html#strftime-strptime-behavior
Deletions:
from datetime import date, timedelta


Revision [1495]

Edited on 2010-07-11 23:32:54 by KlenwellAdmin [Replaces old-style internal links with new pipe-split links.]
Additions:
reference: http://docs.python.org/library/datetime.html#tzinfo-objects
For a Google App Engine project I'm working on, I have to sync the app's time zone, which on the App Engine servers is UTC, to a Google Analytic profile's (i.e. site's) time zone, which [[http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55512 defaults to US/Pacific]].
Deletions:
For a Google App Engine project I'm working on, I have to sync the app's time zone, which on the App Engine servers is UTC, to a Google Analytic profile's (i.e. site's) time zone, which [[http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55512 defaults to US/Pacific]]


Revision [1494]

Edited on 2010-07-11 23:29:43 by KlenwellAdmin [Replaces old-style internal links with new pipe-split links.]
Additions:
====Time Zones====
For a Google App Engine project I'm working on, I have to sync the app's time zone, which on the App Engine servers is UTC, to a Google Analytic profile's (i.e. site's) time zone, which [[http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55512 defaults to US/Pacific]]
Sample Code:
from datetime import datetime, timedelta
GA_OFFSET=-8 # PST (offset from UTC -- ignoring DST)
def sync_now():
return datetime.utcnow() + timedelta(hours=GA_OFFSET)
def sync_today():
return sync_now().date()


Revision [1484]

Edited on 2010-07-09 14:16:20 by KlenwellAdmin [Replaces old-style internal links with new pipe-split links.]
Additions:
from datetime import date, timedelta
Deletions:
from datetime import date


Revision [1483]

The oldest known version of this page was created on 2010-07-09 14:05:59 by KlenwellAdmin [Replaces old-style internal links with new pipe-split links.]