This question already has answers here:
How to convert integer into date object python?
(4 answers)
How to convert a specific integer to datetime in python
(1 answer)
int to datetime in Python [duplicate]
(1 answer)
Closed 1 year ago.
I need to build a way to automate file names, and I was curious as to if there is a function or a quick way to take in 8 digits and output the corresponding Date.
Specifically I only need the Month and year.
Example: 03232021 -> Mar2021
I was trying pandas to_datetime but it didn't seem like it was what I needed.
In [133]: s = "03232021"
In [134]: dt.datetime.strptime(s, "%m%d%Y").date()
Out[134]: datetime.date(2021, 3, 23)
Related
This question already has answers here:
Convert Pandas Column to DateTime
(8 answers)
How to change the datetime format in Pandas
(8 answers)
Closed last month.
I want to convert the date column in my dataframe which is in the format of Dec. 01, 2022 to 12-01-2022
I tried using map function and by importing calender as well
This question already has answers here:
How can I convert a string into a date object and get year, month and day separately?
(4 answers)
Closed 2 months ago.
I have a bunch of number sequences like "221201" meaning the year 2022, month 12 and day 01 (so 2022-12-01). How can I convert number sequences in this format into the actual date using python?
I've tried using the dateutil library but couldn't figure out how to get it to recognize this format.
from datetime import datetime
date_str = '221201'
date_obj = datetime.strptime(date_str, '%y%m%d')
print(type(date_obj))
print(date_obj) # printed in default format
You can learn more about strptime in this link
This question already has answers here:
How to convert a date string to different format [duplicate]
(2 answers)
Closed 1 year ago.
I have a date say - 25-Jan-19
I want to convert it to - Jan19 in python. What date format I'll have to use to get this?
If 25-Jan-19 is a string and will always be in this format, you can try this:-
date = date.split("-")
date = "".join(date[i] for i in range(1,len(date)))
This question already has answers here:
Pandas Timedelta in Days
(5 answers)
Closed 3 years ago.
So, I have a pandas dataframe with a lot of variables including start/end date of loans.
I subtract these two in order to get their difference in days.
The result I get is of the type i.e. 349 days 00:00:00.
How can I keep only for example the number 349 from this column?
Check this format,
df['date'] = pd.to_timedelta(df['date'], errors='coerce').days
also, check .normalize() function in pandas.
This question already has answers here:
How to convert a given ordinal number (from Excel) to a date
(5 answers)
Closed 7 years ago.
I have this list of integers and need to convert it to date using python.
42222 should be 8/6/2015
42290 should be 10/13/2015
42319 should be 11/11/2015
I get the equal date of the integer when i paste in to excel then format the cell to Date.
Excel dates start counting around the year 1900. This will do it:
from datetime import datetime, timedelta
def xldate_to_datetime(xldate):
tempDate = datetime(1900, 1, 1)
deltaDays =timedelta(days=int(xldate)-2)
TheTime = (tempDate + deltaDays )
return TheTime.strftime("%m/%d/%Y")
>>> xldate_to_datetime(42290)
'10/13/2015'