0

how to change next data in database:

jsonData = [{"given_date": "2 1.05. 2002 year"}] 

to

jsonData = [{"given_date": "21.05.2002"}]
2
  • try to replace date value with regex preg_replace('/\s|[a-zA-Z]/', '', '2 1.05. 2002 year'); Commented Dec 14, 2019 at 11:47
  • did it work to u? Commented Dec 17, 2019 at 3:43

1 Answer 1

1

Postgresql update with regex:

UPDATE table
SET given_date = regexp_replace(given_date, '(\s|[a-zA-Z])', '','');

regexp_replace takes the value in given_date and be replaced by third parameter (empty string), according to the second regular parameter (match the spaces and alphabets). The fourth parameter is option like 'g(global)', 'i(ignore case)';

Postgresql regexp_replace reference

Laravel update with regex:

\DB::table('tablename')
->where(...)
->update([
'given_date' => \DB::raw("regexp_replace(given_date, '(\s|[a-zA-Z])', '','')")
]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.