Convert one date time format into another in PHP custom function

I am importing a field into wordpress using WP All Import plugin (XML import). Field name is “ExpiryDate”. Date is in the format “dd/MM/yyyy hh:mm:ss”. I need to convert it to the format “yyyy-MM-dd hh:mm:ss”.

Either this needs to be done via custom function or single line code. Can you guys please help me?

I tried to search online but could not find anything which address the problem via custom function or single line code.

Hi @vineetgoyalhuf and welcome to the forum.

Try this to extract the year, month, day and time then add the obtained values:

http://php.net/manual/en/function.substr.php

Thanks. It was helpful. It worked.

There is a function for this:-

http://php.net/manual/en/datetime.createfromformat.php

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.