<jupyter_start><jupyter_text>Working with Dates When working with dates and time zone, it is recommended that you install a package called [pytz](http://pytz.sourceforge.net/).It is also recommended that you work initally in UTC time zone and then convert to whatever time zone you need in the final output.For date format options, see this [site](http://strftime.org/).<jupyter_code>from datetime import datetime
import pytz
from pytz import timezone<jupyter_output><empty_output><jupyter_text>Creating a date as of now in UTC<jupyter_code>mydate_with_time_utc = datetime.now(pytz.UTC)
mydate_with_time_utc<jupyter_output><empty_output><jupyter_text>Creating a date from arbitrary integers in UTC<jupyter_code>mydate_utc = datetime(2014,11,28,12,30,0,0,pytz.UTC)
mydate_utc<jupyter_output><empty_output><jupyter_text>Creating a date from a UTC time zone to Eastern time zone:<jupyter_code>eastern = timezone('US/Eastern')
mydate_as_edt = mydate_utc.astimezone(eastern)
mydate_as_edt<jupyter_output><empty_output><jupyter_text>Finding Difference Between Dates<jupyter_code>from datetime import datetime
from datetime import timedelta

date_now = datetime.now()
some_date = datetime(2014,12,18,12,0,0,0)
date_diff = some_date - date_now

print('Difference between these 2 dates in days is:', date_diff.days, 'days')
print('and the number of seconds left over is:', date_diff.seconds, 'seconds')<jupyter_output>Difference between these 2 dates in days is: 17 days
and the number of seconds left over is: 73834 seconds<jupyter_text>Adding a Date Let's add 100 days from the current date:<jupyter_code>new_date = datetime.now() + timedelta(days=100)
new_date<jupyter_output><empty_output><jupyter_text>Formating a date: But, let's format this datetime object to mm/dd/YYYY format:<jupyter_code>new_date.strftime('%m/%d/%Y')<jupyter_output><empty_output><jupyter_text>Creating a date from a string or parsing a string as a date:<jupyter_code>dt = datetime.strptime("07/04/1990 16:30", "%m/%d/%Y %H:%M")
dt<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0980295566502463, 'fraction_numerical': 0.026600985221674877, 'mean_word_length': 7.67948717948718, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '626050', 'license': 'MIT', 'n_tokens_mistral': 745, 'n_tokens_neox': 699, 'n_words': 189, 'path': 'dates/WorkingWithDates.ipynb', 'repo_name': 'manual123/Nacho-Jupyter-Notebooks', 'size': '2030'}