Skip to content
Advertisement

WP All Import Pro Function To Change Date And Time Format (From Imported .CSV)

I have a .csv file which I import in my WordPress website using WP All Import Pro. Everything works fine but since I need the date to be in a different format then it comes in the .csv, and seperate the time from the date, and the date from the time I was wondering how to do this.

Example:
**08/11/2020 17:14** (OLD DATE & TIME; FROM .CSV) ( **{pick_up_time[1]}** )

2020-11-08 17:14:00 (NEW DATE & TIME; BASED ON THE OLD DATE & TIME)
2020-11-08 (NEW DATE ONLY; BASED ON THE OLD DATE & TIME)
17:14:00 (NEW TIME ONLY; BASED ON THE OLD DATE & TIME)

It is possible to use functions in the function editor in the import set up.

I want to use the data in custom fields;

end_datetime: {pick_up_time[1]} (2020-11-08 17:14:00)
end_date: {pick_up_time[1]} (2020-11-08)
end_time: {pick_up_time[1]} (17:14:00)


I’m not an expert in php, but I’m willing to learn. Someone who can steer me in the right direction?

Advertisement

Answer

Solved my own question. You can use Strtotime and echo it as date. It wil convert the date as needed.

[date( "Y-m-d H:i:s", strtotime( {pick_up_time[1]} ) )]
[date( "Y-m-d", strtotime( {pick_up_time[1]} ) )]
[date( "H:i", strtotime( {pick_up_time[1]} ) )]

Edit: Must replace string when using strtotime with date. 08/11/2020 17:14 (has /)

Should be:

[date( "Y-m-d H:i:s", strtotime( str_replace("/",".",{pick_up_time[1]}) ) )]
[date( "Y-m-d", strtotime( str_replace("/",".",{pick_up_time[1]}) ) )]
[date( "H:i:s", strtotime( str_replace("/",".",{pick_up_time[1]}) ) )]

For the correct format.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement