Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help regarding date format
#1
hi,

i have date like this 31-12-2024 (dd-mm-yyyy) and i want to convert this date to Dec, 2024. How can i do that.


date = 31-12-2024


l_dt = datetime.datetime.strptime(date, '%d-%M-%Y')
l_dt = l_dt.strftime('%b; %Y')
and it prints Jan, 2024 but it should print Dec, 2024

any help?
Reply
#2
Month input string should be a little m, big M is minute.
l_dt = datetime.datetime.strptime(date, '%d-%m-%Y')
Reply
#3
Thank you so much
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare current date on calendar with date format file name Fioravanti 1 126 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  Python date format changes to date & time 1418 4 518 Jan-20-2024, 04:45 AM
Last Post: 1418
  Modifying a date format jehoshua 17 2,870 Oct-29-2022, 08:44 PM
Last Post: jehoshua
  Date format error getting weekday value Aggie64 2 1,378 May-29-2022, 07:04 PM
Last Post: Aggie64
  Convert Date to another format lonesoac0 2 1,632 Mar-17-2022, 11:26 AM
Last Post: DeaD_EyE
  Format SAS DATE Racer_x 0 966 Feb-09-2022, 04:44 PM
Last Post: Racer_x
  How can I compare 2 format of date? korenron 4 1,495 Dec-21-2021, 12:40 PM
Last Post: korenron
  Date format and past date check function Turtle 5 4,076 Oct-22-2021, 09:45 PM
Last Post: deanhystad
  Print first day of the week as string in date format MyerzzD 2 1,980 Sep-29-2021, 06:43 AM
Last Post: MyerzzD
  String to Date format SAF 2 2,412 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