Python Forum
Update Date based on Time/String
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Update Date based on Time/String
#2
There are probably several ways to do this in python. You could simply open the file and process each line, then write it to stdout. Here is one way to process a single line
>>> import datetime as dt
>>> day = dt.timedelta(days=1)
>>> 
>>> s = "15,08/01/2020 0000,778,0,82"
>>> e = s.split(',', 2)
>>> e
['15', '08/01/2020 0000', '778,0,82']
>>> if e[1].endswith('0000'):
...     d = dt.datetime.strptime(e[1].split()[0], '%d/%M/%Y')
...     e[1] = '{:%d/%M/%Y} 0000'.format(d + day)
...     s = ','.join(e)
... 
>>> s
'15,09/01/2020 0000,778,0,82'
Reply


Messages In This Thread
Update Date based on Time/String - by stevezemlicka - Jan-08-2021, 05:49 PM
RE: Update Date based on Time/String - by Gribouillis - Jan-08-2021, 06:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare current date on calendar with date format file name Fioravanti 1 279 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  Date Time Series Help...Please spra8560 2 405 Feb-01-2024, 01:38 PM
Last Post: spra8560
  Create dual folder on different path/drive based on the date agmoraojr 2 473 Jan-21-2024, 10:02 AM
Last Post: snippsat
  Python date format changes to date & time 1418 4 663 Jan-20-2024, 04:45 AM
Last Post: 1418
  Downloading time zone aware files, getting wrong files(by date))s tester_V 9 1,080 Jul-23-2023, 08:32 AM
Last Post: deanhystad
  Formatting a date time string read from a csv file DosAtPython 5 1,366 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  Wait til a date and time KatManDEW 2 1,456 Mar-11-2022, 08:05 PM
Last Post: KatManDEW
  String concatenation in SQL update statement hammer 3 1,567 Feb-24-2022, 08:00 PM
Last Post: hammer
  Date format and past date check function Turtle 5 4,331 Oct-22-2021, 09:45 PM
Last Post: deanhystad
  Print first day of the week as string in date format MyerzzD 2 2,055 Sep-29-2021, 06:43 AM
Last Post: MyerzzD

Forum Jump:

User Panel Messages

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