1

I'm struggling to solve this problem in Notepad++. I'd really appreciate a good answer.

Let's say I have this line:

INSERT INTO example VALUES ('P1', 'V1', '27-Apr-2004', 20.00, '123', '1234');

And I want to get this:

INSERT INTO example VALUES ('P1', 'V1', '2004-04-27', 20.00, '123', '1234');

How can I do this for all lines in Notepad++? I've tried different kind of things but I couldn't get this result.

2
  • I would use one regex to change the order of day, month and year, e.g. 27-Apr-2004 would become 2004-Apr-27, then use 12 separate replacements for the month names, i.e. replace -Apr- with -04- etc. If a leading 0 is necessary for the day, you might need another regex replacement. The whole taskmight be easier to solve with a script (awk, perl, python, ...).
    – Bodo
    Oct 7, 2021 at 13:25
  • If the type of the field is date or datetime, it might be easier to insert some kind of database specific conversion function into your SQL. For instance, for SQL Server that could look like cast('27-Apr-2004' as date). Find what would then be ('\d{1,2}-\l{3}-\d{4}'), and Replace with: cast\(\1 as date\)
    – Berend
    Oct 7, 2021 at 14:11

0

You must log in to answer this question.

Browse other questions tagged .