Title: Date Convert to Text
Last modified: April 30, 2018

---

# Date Convert to Text

 *  Resolved [chemistrap](https://wordpress.org/support/users/chemistrap1/)
 * (@chemistrap1)
 * [8 years ago](https://wordpress.org/support/topic/date-convert-to-text/)
 * Hello again,
    I’m importing products which type is books. And there has some 
   custom specification like published date. But this date like 2018/04 in my xml
   file. But i want to convert this to April 2018.
 * How can i do that in my local date (tr_TR) ?
    Thank you
    -  This topic was modified 8 years ago by [chemistrap](https://wordpress.org/support/users/chemistrap1/).

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

 *  [duceduc](https://wordpress.org/support/users/duceduc/)
 * (@duceduc)
 * [8 years ago](https://wordpress.org/support/topic/date-convert-to-text/#post-10245105)
 * Here is one you can use. This will output ‘April 2018’
 * You will need to add this to your wp all import function editor.
 *     ```
       function formatDate($str) {
         $yr = preg_replace('#\/[^/]*$#', '', $str);
         $month = preg_replace('/^.*\/\s*/', '', $str);
         $mth = 'Invalid Month';
   
         if($month >= 1 && $month <= 12){
           $mth = date("F", strtotime("2001-" . $month . "-01"));
         }
         return $mth.' '.$yr;
       }
       ```
   
 * Call it as such.
    `[formatDate({yourXmlDate[1]})]`
 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [8 years ago](https://wordpress.org/support/topic/date-convert-to-text/#post-10252365)
 * Hi [@chemistrap1](https://wordpress.org/support/users/chemistrap1/)
 * You can do this with a custom PHP function: [http://www.wpallimport.com/documentation/developers/execute-php/](http://www.wpallimport.com/documentation/developers/execute-php/)(
   as mentioned by [@duceduc](https://wordpress.org/support/users/duceduc/) above).
 * It looks like this snippet above should work, and here’s another example snippet
   in case it helps:
 *     ```
       function changeDate( $date ) {
       	if ( $dateObj = DateTime::createFromFormat( "Y/m", $date ) ) {
       		return $dateObj->format( "F Y" );
       	} else {
       		return $date;
       	}
       }
       ```
   
    -  This reply was modified 8 years ago by [WP All Import](https://wordpress.org/support/users/wpallimport/).
 *  Thread Starter [chemistrap](https://wordpress.org/support/users/chemistrap1/)
 * (@chemistrap1)
 * [8 years ago](https://wordpress.org/support/topic/date-convert-to-text/#post-10253103)
 * Thank you for help. I guess your snipper code more logical other but thanks anyway
   to guys.
 *  Thread Starter [chemistrap](https://wordpress.org/support/users/chemistrap1/)
 * (@chemistrap1)
 * [8 years ago](https://wordpress.org/support/topic/date-convert-to-text/#post-10265134)
 * [@duceduc](https://wordpress.org/support/users/duceduc/) your code was work but
   only translate problem occured. How can i handle that?
    Thank you.
 *  Thread Starter [chemistrap](https://wordpress.org/support/users/chemistrap1/)
 * (@chemistrap1)
 * [8 years ago](https://wordpress.org/support/topic/date-convert-to-text/#post-10280884)
 * [@duceduc](https://wordpress.org/support/users/duceduc/) thank you so much again.
   
   I handle localization with i18n
 * if change your code like that
 *     ```
       function formatDate($str) {
         $yr = preg_replace('#\/[^/]*$#', '', $str);
         $month = preg_replace('/^.*\/\s*/', '', $str);
         $mth = 'Invalid Month';
   
         if($month >= 1 && $month <= 12){
           $mth = date_i18n("F", strtotime("2001-" . $month . "-01"));
         }
         return $mth.' '.$yr;
       }
       ```
   
 * it worked like what exactly want.
 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [7 years, 12 months ago](https://wordpress.org/support/topic/date-convert-to-text/#post-10291489)
 * I’m marking this as resolved, but feel free to continue the custom code discussion
   in this thread if you’d like.

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

The topic ‘Date Convert to Text’ is closed to new replies.

 * ![](https://ps.w.org/wp-all-import/assets/icon-256x256.png?rev=2570179)
 * [WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets](https://wordpress.org/plugins/wp-all-import/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-all-import/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-all-import/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-all-import/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-all-import/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-all-import/reviews/)

 * 6 replies
 * 3 participants
 * Last reply from: [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * Last activity: [7 years, 12 months ago](https://wordpress.org/support/topic/date-convert-to-text/#post-10291489)
 * Status: resolved