Python Forum
Convert text file date into specific format
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert text file date into specific format
#8
>>> line = '2018/01/03 cccccc'
>>> date = line.split()[0].replace('/', '')
>>> date
'20180103'
>>> new_line = f'{date}{line[line.index(" "):]}'
>>> new_line
'20180103 cccccc'
For examaple. Or you can modify it to use datetime. Try with datetime because you are working with dates so you have to practise.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Messages In This Thread
RE: Convert text file date into specific format - by wavic - May-14-2018, 08:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Invalid Date Format fo Cached Files jland47 1 223 May-22-2024, 07:04 PM
Last Post: deanhystad
  Compare current date on calendar with date format file name Fioravanti 1 383 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
Question [SOLVED] Correct way to convert file from cp-1252 to utf-8? Winfried 8 1,424 Feb-29-2024, 12:30 AM
Last Post: Winfried
  Extracting specific file from an archive tester_V 4 661 Jan-29-2024, 06:41 PM
Last Post: tester_V
  Python date format changes to date & time 1418 4 810 Jan-20-2024, 04:45 AM
Last Post: 1418
Thumbs Up Convert word into pdf and copy table to outlook body in a prescribed format email2kmahe 1 848 Sep-22-2023, 02:33 PM
Last Post: carecavoador
  Color a table cell based on specific text Creepy 11 2,383 Jul-27-2023, 02:48 PM
Last Post: deanhystad
  Convert File to Data URL michaelnicol 3 1,380 Jul-08-2023, 11:35 AM
Last Post: DeaD_EyE
  Formatting a date time string read from a csv file DosAtPython 5 1,588 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  Python Script to convert Json to CSV file chvsnarayana 8 2,747 Apr-26-2023, 10:31 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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