Python Forum
Date to integer? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Date to integer? (/thread-18443.html)



Date to integer? - Scott - May-18-2019

HI everyone,

I am looking to convert a date to integer, how do I go about this? column below
Qtr-Year
Mar-90	
Jun-90
Sep-90
Dec-90
Mar-91
do I first need to change the date format to '031990' etc then change it to a str then interger?

I appreciate any help
Thanks


RE: Date to integer? - heiner55 - May-18-2019

Convert it into a datetime object:
See here: https://python-forum.io/Thread-help-with-converting-C-function-to-Python

Or convert into a time object:
See here: https://docs.python.org/3.7/library/time.html


RE: Date to integer? - buran - May-18-2019

better if year is firs and then month, e.g. 9003, 9006, etc. this will allow to sort the integers in correct order