Date Time split in python
Question: I have to split a date time which I get from a software in the below format to
separate variables (year,month,day,hour, min,sec)

    
    
    19 Nov 2015  18:45:00.000
    

Note : There is two spaces between the date and time. The whole date and time
is stored in a single string variable. Please help me in this regards.

Thanks in advance.


Answer: As an alternative to wim's
[answer](http://stackoverflow.com/a/33811125/189134), 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`](https://docs.python.org/2/library/datetime.html#strftime-and-
strptime-behavior) to parse the string.

