• Resolved marinersspace

    (@marinersspace)


    I have a csv file showing date as “YYYY-mm-dd hh:mm:ss” or “None”
    But for import I need time format as mm/dd/YYYY hh:mm AM/PM

    I am not that good with coding skills but managed to make a small change date function program would like to get input for the function or even suggestions if you can.

    function change_date ($date_end) {
    	if ($date_end=="None"){
    		echo "12/31/2019";
    	}
    	else{
    	echo date_format($date_end,'m/d/Y H:i A');
    	}
    }
    

    hope my program makes some sense to you.
    The program sometime worked on the localhost but failed on the live server.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @marinersspace

    But for import I need time format as mm/dd/YYYY hh:mm AM/PM

    Here’s an example function you can use:

    function my_fix_date( $date = '', $format = 'Ymd', $new_format = 'Y/m/d' ) {
    	if ( empty( $date ) || $date == 'None' ) return "12/31/2019";
    	
    	if ( $obj = DateTime::createFromFormat( $format, $date ) ) {
    		return $obj->format( $new_format );	
    	} else {
    		return null;
        }
    }

    Example usage:

    [my_fix_date({date[1]},"Y-m-d H:i:s","m/d/Y H:i A")]

    Just change {date[1]} to the import element from your file that contains the date.

    • This reply was modified 6 years, 7 months ago by WP All Import.
    Thread Starter marinersspace

    (@marinersspace)

    Thank you for your quick response. This function has worked properly. It has even helped me resolve the technical issues arising due to my theme not fully compatible with your plugin.
    Thank you for your support.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘csv time format and import time format different causing issues’ is closed to new replies.