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.
Add timezone to date in text files using regex Topic is solved
Re: Add timezone to date in text files using regex Topic is solved
Code: Select all
NewText := RegExReplace(Text, "\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}", "$0 CET")
Re: Add timezone to date in text files using regex
@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?
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?
Re: Add timezone to date in text files using regex
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.
Re: Add timezone to date in text files using regex
@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.
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.