How to convert DateTime to integer in Python Last Updated : 30 Aug, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report Python provides a module called DateTime to perform all the operations related to date and time. It has a rich set of functions used to perform almost all the operations that deal with time. It needs to be imported first to use the functions and it comes along with python, so no need to install it separately. Here, we deal with a special date object. So to convert the given date to integer, we can follow the following method. Method 1: Using multiplication with 100's In this method, we will multiply each component, of the date with multiples of 100 and add them all to convert them into integers. Python3 # importing the datetime module import datetime # Getting todays date and time using now() of # datetime class current_date = datetime.datetime.now() # Printing the current_date as the date object itself. print("Original date and time object:", current_date) # Retrieving each component of the date # i.e year,month,day,hour,minute,second and # Multiplying with multiples of 100 # year - 10000000000 # month - 100000000 # day - 1000000 # hour - 10000 # minute - 100 print("Date and Time in Integer Format:", current_date.year*10000000000 + current_date.month * 100000000 + current_date.day * 1000000 + current_date.hour*10000 + current_date.minute*100 + current_date.second) Output: Original date and time object: 2021-08-10 15:51:25.695808 Date and Time in Integer Format: 20210810155125Method 2: Using datetime.strftime() object In this method, we are using strftime() function of datetime class which converts it into the string which can be converted to an integer using the int() function. Syntax : strftime(format) Returns : It returns the string representation of the date or time object. Code: Python3 # importing the datetime module import datetime # Getting todays date and time using now() of datetime # class current_date = datetime.datetime.now() # Printing the current_date as the date object itself. print("Original date and time object:", current_date) # Using the strftime() of datetime class # which takes the components of date as parameter # %Y - year # %m - month # %d - day # %H - Hours # %M - Minutes # %S - Seconds print("Date and Time in Integer Format:", int(current_date.strftime("%Y%m%d%H%M%S"))) Output: Original date and time object: 2021-08-10 15:55:19.738126 Date and Time in Integer Format: 20210810155519 Comment More infoAdvertise with us Next Article How to convert DateTime to integer in Python M magichat Follow Improve Article Tags : Python Python-datetime Practice Tags : python Similar Reads How to convert datetime to date in Python In this article, we are going to see how to convert DateTime to date in Python. For this, we will use the strptime() method and Pandas module. This method is used to create a DateTime object from a string. Then we will extract the date from the DateTime object using the date() function and dt.date f 3 min read How to Convert Integer to Datetime in Pandas DataFrame? Let's discuss how to convert an Integer to Datetime in it. Now to convert Integers to Datetime in Pandas DataFrame. Syntax of  pd.to_datetimedf['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)Create the DataFrame to Convert Integer to Datetime in Pandas Check 2 min read How to Convert DateTime to UNIX Timestamp in Python ? Generating a UNIX timestamp from a DateTime object in Python involves converting a date and time representation into the number of seconds elapsed since January 1, 1970 (known as the Unix epoch). For example, given a DateTime representing May 29, 2025, 15:30, the UNIX timestamp is the floating-point 2 min read Datetime to integer timestamp in Python A timestamp represents the number of seconds that have passed since January 1, 1970, 00:00:00 UTC (also known as the epoch). We can convert a datetime object to a timestamp using the built-in timestamp() method, and then round or typecast it to get an integer version. In this article, we'll learn ho 3 min read Converting string into DateTime in Python The goal is to convert a date string like "2021/05/25" into a Python-recognized DateTime object such as 2021-05-25 00:00:00. This enables accurate and consistent date operations like comparisons, calculations and formatting when working with time-related data from sources like files or user input. L 2 min read Like