Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

convert into date python

from datetime import datetime

datetime_str = '09/19/18 13:55:26'

datetime_object = datetime.strptime(datetime_str, '%m/%d/%y %H:%M:%S')

print(type(datetime_object))
print(datetime_object)  # printed in default format
Comment

convert into date python

date_str = '09-19-2018'

date_object = datetime.strptime(date_str, '%m-%d-%Y').date()
print(type(date_object))
print(date_object)  # printed in default formatting
Comment

convert datetime to date python

datetime.datetime.now().date()
Comment

How to convert datetime in python

#How to convert datetime in python like below:

df.Start_Time

#         2016-02-08 00:37:08
#         2016-02-08 05:56:20


df.Start_Time = pd.to_datetime(df.Start_Time)
Comment

datetime convert python

# input: 07:40:01PM
# output: 19:40:01

# First System:

def timeConversion(s):
    period = s[-2:]
    time = s[:-2]
    hour = int(time[:2])
    
    if period == 'PM' and hour < 12:                
        time = str(hour + 12) + time[2:]

    if period == 'AM' and hour == 12:
        time = '00' + time[2:]
        
    return time
s = input()
print(timeConversion(s))

# second code and use to module:

"""
from datetime import*
def timeConversion(s):
    return datetime.strftime(datetime.strptime(s, "%I:%M:%S%p"), "%H:%M:%S")
if __name__ == '__main__':
    s = input()
    print(timeConversion(s))
    
"""

# 3rd code and not used module.

'''

time = input()                  # time = input time.
sp = time.split(':')            # sp = split the ":"
if 'PM' in sp[2]:
    sp[0] = int(sp[0])+12
    sp[2] = sp[2].rstrip('PM')
elif 'AM' in sp[2]:
    sp[2] = sp[2].rstrip('AM')
    if sp[0] == '12':
        sp[0] = "0"
con_time = ''             # con_time = convert time.
for i in range(2):
    con_time += str(sp[i])+':'
con_time += sp[2]
print(con_time)
'''

Comment

PREVIOUS NEXT
Code Example
Python :: python - count how many unique in a column 
Python :: plot background color matplotlib 
Python :: Module "django.contrib.auth.hashers" does not define a "BcryptPasswordHasher" attribute/class 
Python :: python remove duplicate numbers 
Python :: check pyenv version windows 
Python :: django models.py convert DateTimeField to DateField 
Python :: python program for swapping position of two numbers 
Python :: python for k, v in dictionary 
Python :: raise exception in python 
Python :: How to install pandas-profiling 
Python :: numpy array length 
Python :: get root path python 
Python :: how to convert decimal to binary python 
Python :: inverse list python 
Python :: pandas series to tuple list 
Python :: Chi-Squared test in python 
Python :: get month day year 12 hour time format python 
Python :: how to print answer 2 decimal places in python 3 
Python :: date.month date time 
Python :: reload flask on change 
Python :: python import file from parent directory 
Python :: tensorflow bert implementation 
Python :: seaborn correlation heatmap 
Python :: is python platform independent 
Python :: empty dictionary python 
Python :: python recursively print directory 
Python :: find different between list 
Python :: pandas pass two columns to function 
Python :: doc2vec similarity 
Python :: how to send file using socket in python 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =