Date Time split in python

First pip install python-dateutil then do:

>>> from dateutil.parser import parse
>>> dt = parse('19 Nov 2015  18:45:00.000')
>>> dt.year
2015
>>> dt.month
11
>>> dt.day
19
>>> dt.hour
18
>>> dt.minute
45
>>> dt.second
0

As an alternative to wim's answer, if you don't want to install a package, you can do it like so:

import datetime

s = "19 Nov 2015  18:45:00.000"
d = datetime.datetime.strptime(s, "%d %b %Y  %H:%M:%S.%f")

print d.year
print d.month
print d.day
print d.hour
print d.minute
print d.second

This outputs:

2015
11
19
18
45
0

This utilizes strptime to parse the string.


Below solution should work for you:

import datetime

string = "19 Nov 2015  18:45:00.000"
date = datetime.datetime.strptime(string, "%d %b %Y  %H:%M:%S.%f")

print date

Output would be:

2015-11-19 18:45:00

And you can access the desired values with:

>>> date.year
2015
>>> date.month
11
>>> date.day
19
>>> date.hour
18
>>> date.minute
45
>>> date.second
0

You can check datetime's package documentation under section 8.1.7 for srtptime function's usage.