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
#9
Thanks. I solve it
This is my code. Is there any comment with my code, or any suggestion.

import datetime as dt
from datetime import datetime
with open('holiday.txt') as f, open('new.txt', 'w') as f_out:
    for line in f:
        line = line.strip()
	#line =line.replace('/', '')
	#f_out.write('{}\n'.format(line))
	#f_out.write(datetime.strftime(datetime.strptime(line, '%Y/%m/%d'), '%Y%m%d'))
	line.rstrip().split('  ')
	line_1 = line.split()[0]
	line_2 = line.split()[1]
	newline =(datetime.strftime(datetime.strptime(line_1, '%Y/%m/%d'), '%Y%m%d'))
	#result = line_1 +" " +line_2
	#f_out.write(result)
	f_out.write(line_1 +" " +line_2+ '\n')
Reply


Messages In This Thread
RE: Convert text file date into specific format - by jacklee26 - May-15-2018, 05:38 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 382 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,423 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 847 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,746 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