Add timezone to date in text files using regex Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
bazkeys
Posts: 98
Joined: 20 Jan 2021, 21:58

Add timezone to date in text files using regex

Post by bazkeys » 31 Jul 2021, 04:20

I'm looking to make a simple change to dates in text files. I'm looking to add CET to the end of any date.
The date format is straightforward, it's always yyyy/mm/dd hh:mm:ss
So for example, if I have 2021/07/31 17:18:55 this should be outputted as 2021/07/31 17:18:55 CET. I think it should be easy enough, but my old brain is addled. Thanks for any help.

User avatar
boiler
Posts: 16933
Joined: 21 Dec 2014, 02:44

Re: Add timezone to date in text files using regex  Topic is solved

Post by boiler » 31 Jul 2021, 04:33

Code: Select all

NewText := RegExReplace(Text, "\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}", "$0 CET")

bazkeys
Posts: 98
Joined: 20 Jan 2021, 21:58

Re: Add timezone to date in text files using regex

Post by bazkeys » 31 Jul 2021, 06:32

@boiler
Thank you once again.

I know I didn't ask it, but if I did want to change the hour, is there an easy way to do it, say if I wanted to add 1 hour?

User avatar
boiler
Posts: 16933
Joined: 21 Dec 2014, 02:44

Re: Add timezone to date in text files using regex

Post by boiler » 31 Jul 2021, 06:58

It's not as simple as a change to the RegEx pattern because increasing an hour could change the date, so you have to extract the date/time, convert it to the proper format for acting on it, increase it by an hour using EnvAdd or equivalent, convert it back to the original format, then place back in the location in the text with CET added.

bazkeys
Posts: 98
Joined: 20 Jan 2021, 21:58

Re: Add timezone to date in text files using regex

Post by bazkeys » 01 Aug 2021, 08:24

@boiler
Thanks, yeah that makes sense. Think I'll try to avoid tinkering with the dates for now then, but good to know what I have to take into account if I end up doing it.

Post Reply

Return to “Ask for Help (v1)”