Python Forum
How to convert dates in odd format to months
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to convert dates in odd format to months
#1
So I have a column called 'age' in my sql column that is inconsistent in format. It lists ages of kids in days, weeks or months. For example:

Output:
0d 6d 7d 1w, 3d 7w, 5d 4m 5m
What I want to do is convert that into months, like, anyone under 30 days would be 0 months, anyone between 1-2 months would be 1 month, etc. The max-age I have is seven months, so it would be changed to one of eight categories: 0,1,2,3,4,5,6,7.

I was thinking of a clunky way of doing it, like searching to see if there is a 'w', and if so, remove the w and everything after the w, and take that number. Do the same for days, and then for months. But I am sure there has to be a cleaner way?
Reply


Messages In This Thread
How to convert dates in odd format to months - by lokhtar - Apr-17-2021, 12:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Thumbs Up Convert word into pdf and copy table to outlook body in a prescribed format email2kmahe 1 759 Sep-22-2023, 02:33 PM
Last Post: carecavoador
  Convert Json to table format python_student 2 5,556 Sep-28-2022, 12:48 PM
Last Post: python_student
  Convert .xlsx to Format as Table bnadir55 0 894 Aug-11-2022, 06:39 AM
Last Post: bnadir55
  how to convert and format a varable darktitan 4 1,697 May-29-2022, 12:59 PM
Last Post: darktitan
  Convert Date to another format lonesoac0 2 1,679 Mar-17-2022, 11:26 AM
Last Post: DeaD_EyE
  Illegal instruction? working code for months? korenron 4 13,119 Aug-05-2021, 09:57 AM
Last Post: korenron
  Convert timedelta to specified format Planetary_Assault_Systems 3 3,206 Jun-27-2021, 01:46 PM
Last Post: snippsat
  Matplotlib: How do I convert Dates from Excel to use in Matplotlib JaneTan 1 3,251 Mar-11-2021, 10:52 AM
Last Post: buran
  Convert email addresses to VCF format jehoshua 2 4,693 Mar-06-2021, 12:50 AM
Last Post: jehoshua
  Convert date integers (ex. 43831) to regular format Galven 2 2,640 Nov-15-2020, 11:38 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020