-1

How do I convert 20230102 to Monday?

Using python, I need to accomplish this. I have a column of numbers in the format yyyymmdd.

2
  • Do you use Pandas? Commented Jan 13, 2023 at 5:41
  • I suggest you google "convert string to date python" for some tips. Commented Jan 13, 2023 at 5:41

3 Answers 3

2

Parse with strptime and format with strftime:

>>> from datetime import datetime >>> n = 20230102 >>> datetime.strptime(str(n), "%Y%m%d").strftime("%A") 'Monday' 

See strftime() and strptime() Format Codes for documentation of the % strings.

Sign up to request clarification or add additional context in comments.

Comments

0

You can convert number string into weekday using "datetime" module

import datetime def get_weekday(date): date = datetime.datetime.strptime(date, '%Y%m%d') return date.strftime('%A') print(get_weekday('20230102')) 

This is how you can achieve your desired output.

Comments

0

You can do it with weekday() method.

from datetime import date import calendar my_date = date.today() calendar.day_name[my_date.weekday()] #Friday 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.