Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Modifying a date format
#3
Is this the kind of thing you're looking for?

date_list = ['D4', '7', '2004\n']  # a data sample

for index, item in enumerate(date_list):
    if index == 0:
        month = item.lstrip("D")
        month = "D" + str(f"{int(month):02d}")
    elif index == 1:
        day = str(f"{int(item):02d}")
    else:
        year = item.rstrip("\n")

date = f"{month}/{day}/{year}"
print(date)
Output:
D04/07/2004
jehoshua likes this post
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply


Messages In This Thread
Modifying a date format - by jehoshua - Oct-27-2022, 08:14 PM
RE: Modifying a date format - by deanhystad - Oct-27-2022, 08:53 PM
RE: Modifying a date format - by jehoshua - Oct-27-2022, 09:34 PM
RE: Modifying a date format - by rob101 - Oct-27-2022, 08:59 PM
RE: Modifying a date format - by jehoshua - Oct-28-2022, 03:42 AM
RE: Modifying a date format - by Larz60+ - Oct-27-2022, 09:57 PM
RE: Modifying a date format - by jehoshua - Oct-28-2022, 03:56 AM
RE: Modifying a date format - by Larz60+ - Oct-28-2022, 08:58 AM
RE: Modifying a date format - by jehoshua - Oct-28-2022, 10:17 PM
RE: Modifying a date format - by rob101 - Oct-28-2022, 10:23 AM
RE: Modifying a date format - by jehoshua - Oct-28-2022, 10:34 PM
RE: Modifying a date format - by DeaD_EyE - Oct-28-2022, 12:53 PM
RE: Modifying a date format - by jehoshua - Oct-28-2022, 11:20 PM
RE: Modifying a date format - by rob101 - Oct-28-2022, 10:59 PM
RE: Modifying a date format - by jehoshua - Oct-28-2022, 11:23 PM
RE: Modifying a date format - by jehoshua - Oct-29-2022, 08:44 PM
RE: Modifying a date format - by DeaD_EyE - Oct-29-2022, 03:10 PM
RE: Modifying a date format - by jehoshua - Oct-29-2022, 08:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Invalid Date Format fo Cached Files jland47 1 279 May-22-2024, 07:04 PM
Last Post: deanhystad
  Compare current date on calendar with date format file name Fioravanti 1 470 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  Python date format changes to date & time 1418 4 905 Jan-20-2024, 04:45 AM
Last Post: 1418
  Date format error getting weekday value Aggie64 2 1,540 May-29-2022, 07:04 PM
Last Post: Aggie64
  Convert Date to another format lonesoac0 2 1,794 Mar-17-2022, 11:26 AM
Last Post: DeaD_EyE
  Format SAS DATE Racer_x 0 1,083 Feb-09-2022, 04:44 PM
Last Post: Racer_x
  How can I compare 2 format of date? korenron 4 1,674 Dec-21-2021, 12:40 PM
Last Post: korenron
  Date format and past date check function Turtle 5 4,714 Oct-22-2021, 09:45 PM
Last Post: deanhystad
  Print first day of the week as string in date format MyerzzD 2 2,152 Sep-29-2021, 06:43 AM
Last Post: MyerzzD
  String to Date format SAF 2 2,581 Apr-06-2021, 02:09 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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