I have a file with a few thousand rows to be added to a MySQL database. There are date values in the rows which are in the dd-mm-yyyy format but I need them to be in the yyyy-mm-dd format.
E.g., '11-04-2010',
needs to become '2010-04-11',
in every row.
Is there a simple way to do this in notepad++ or another text editor?
Used Notepad++ to change mm/dd/yyyy to yyyy/mm/dd in several lines of a text file. Script was saved as a macro for next file. Show activity on this post. "(\d{4})-(\d{1,2})-(\d{1,2})T([0-2]\d):([0-5]\d):([0-5]\d)(?:.
Open the text file in Notepad. Click Edit on the menu bar, then select Replace in the Edit menu. Once in the Search and Replace window, enter the text you want to find and the text you want to use as a replacement. See our using search and replace and advanced options section for further information and help.
Using Regex to find and replace text in Notepad++ In all examples, use select Find and Replace (Ctrl + H) to replace all the matches with the desired string or (no string). And also ensure the 'Regular expression' radio button is set.
In Notepad++, press Ctrl-H (Replace...). In the Replace dialog box, click Extended under Search Mode. In the "Find what" box type !\ r and in the "Replace with" box type \r.
You can do this with Textpad:
Find: ([0-9]+)-+([0-9]+)-+([0-9]+)
Replace: \3-\2-\1
To make sure you only reorder wrong formats (in case you have mixed formats from merging databases), use this:
([0-9]{2})-+([0-9]{2})-+([0-9]{4})
This searches for (four digits, dash, two digits, dash, two digits).
In an regex capable editor like notepad++, replace it with this:
\3-\2-\1
In a tool like libre office, you need to replace it with this:
$3-$2-$1
Edit: I wrote a blogpost about this as it seems to be a common problem: http://bytethinker.com/blog/correct-date-format-with-notepad-and-regex
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With