Title: format date
Last modified: August 21, 2016

---

# format date

 *  Resolved [Francesco](https://wordpress.org/support/users/francesco_5005/)
 * (@francesco_5005)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/format-date/)
 * Hi,
 * I used this shortcode for my gallery:
 *     ```
       [mla_gallery columns=2 post_parent=all attachment_category=my_category orderby=date order=desc posts_per_page=10 post_mime_type=application/pdf size=icon link=file mla_caption="{+description+} {+date+}"] 
   
       [mla_gallery post_parent=all attachment_category=my_category orderby=date order=desc posts_per_page=10 post_mime_type=application/pdf mla_output=paginate_links]
       ```
   
 * I’m just wondering if it’s possible to format the date present in the caption
   in d/m/Y .
 * [http://wordpress.org/plugins/media-library-assistant/](http://wordpress.org/plugins/media-library-assistant/)

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

 *  Plugin Author [David Lingren](https://wordpress.org/support/users/dglingren/)
 * (@dglingren)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/format-date/#post-4293396)
 * Thanks for your interest and for this question. In the current MLA version the
   only way to do this would be to use the `[mla_gallery]` Filters and write a bit
   of PHP code to reformat the caption the way you want it.
 * I am on the road and working from memory, so I can’t be too specific. If you 
   go to the Settings/Media Library Assistant Documentation tab and look at the 
   WordPress Filters section you can get the information you need. There is a complete
   example of a small plugin you can adapt to your specific needs. You can add a
   bit of code to the Item Values filter to replace the “date” field with the format
   you want; everything else should be fine.
 * See what you can do with that. I’ll be back home next week and I can give you
   more specific help if you need it. Thanks for your patience and your understanding.
 *  Plugin Author [David Lingren](https://wordpress.org/support/users/dglingren/)
 * (@dglingren)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/format-date/#post-4293439)
 * I am back home and if you are still interested in pursuing this issue I can give
   you more assistance.
 * Let me know if my suggestion to use the `[mla_gallery]` filters is something 
   that would work for you, and if you need more details to implement it.
 * Thanks for your interest and your patience.
 *  Thread Starter [Francesco](https://wordpress.org/support/users/francesco_5005/)
 * (@francesco_5005)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/format-date/#post-4293443)
 * I’ve to thank you for your kindness, now I’m busy on another project, but soon
   I could use this topic as a reference.
 *  Plugin Author [David Lingren](https://wordpress.org/support/users/dglingren/)
 * (@dglingren)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/format-date/#post-4293451)
 * When you get back to this project, here is some code you can use to accomplish
   your goal.
 * Start with the example code you can find in the /plugins/media-library-assistant/
   examples directory, file mla-hooks-example.php.txt
 * Rename the file to remove the “.txt” portion and place it in your /plugins directory.
   You can change the name of the plugin and file if you like.
 * Edit the file and add this block of code just below the `error_log( ...` statement
   in the `public static function mla_gallery_item_values_filter( $item_values )`
   function:
 *     ```
       /*
        * For this first example, we will reformat the 'date' value as d/m/Y. We use a shortcode parameter of our
        * own to do this on a gallery-by-gallery basis, leaving other [mla_gallery] instances untouched.
        */
       if ( isset( self::$shortcode_attributes['my_filter'] ) && 'format date' == self::$shortcode_attributes['my_filter'] ) {
   
       	/*
       	 * Default format is YYYY-MM-DD HH:MM:SS (HH = 00 - 23), or 'Y-m-d H:i:s'
       	 * Convert to UNIX timestamp so any reformat is possible
       	 */
       	$old_date = $item_values['date'];
       	$timestamp = mktime( substr( $old_date, 11, 2 ), substr( $old_date, 14, 2 ), substr( $old_date, 17, 2 ), substr( $old_date, 5, 2 ), substr( $old_date, 8, 2 ), substr( $old_date, 0, 4 ) );
   
       	/*
       	 * Update the $item_values and pass them back from the filter.
       	 * We must also update the caption because it was composed before this filter is called.
       	 */
       	$item_values['date'] = date( 'd/m/Y', $timestamp );
       	$item_values['caption'] = $item_values['description'] . $item_values['date'];
       	return $item_values;
       }
       ```
   
 * Save the file and activate the plugin. Add the `my_filter="format date"` parameter
   to the `[mla_gallery]` shortcode and you should see the captions with the re-
   formatted date. ANy other shortcodes that do not contain the added parameter 
   will be unaffected by the filter.
 * I’m going to mark this topic resolved for now, but feel free to update it if 
   you have any problems or further questions. Thanks for your interest in the plugin.
 *  Plugin Author [David Lingren](https://wordpress.org/support/users/dglingren/)
 * (@dglingren)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/format-date/#post-4293479)
 * Francesco,
 * I just found your post in [another topic](http://wordpress.org/support/topic/using-title-instead-of-caption),
   where you wrote:
 * >  very well everything works fine, I just modified this line:
   > $item_values[‘caption’] = $item_values[‘description’] .” – “. $item_values[‘
   > date’];
   > thanks for your kind assistance.
 * I assume your comment actually refers to the above suggestion to use the MLA 
   plugin filters for date formatting.
 * Thanks for the update and the good news. If you have any problems or further 
   questions, let me know.
 *  Thread Starter [Francesco](https://wordpress.org/support/users/francesco_5005/)
 * (@francesco_5005)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/format-date/#post-4293480)
 * Yes it’s true, sorry for the incovenience, yesterday I had a lot of tabs open
 * anyway, my answer for **this topic** is:
 * very well everything works fine, I just modified this line:
    `$item_values['caption']
   = $item_values['description'] ." - ".$item_values['date'];`

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

The topic ‘format date’ is closed to new replies.

 * ![](https://ps.w.org/media-library-assistant/assets/icon-256x256.png?rev=973502)
 * [Media Library Assistant](https://wordpress.org/plugins/media-library-assistant/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/media-library-assistant/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/media-library-assistant/)
 * [Active Topics](https://wordpress.org/support/plugin/media-library-assistant/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/media-library-assistant/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/media-library-assistant/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [Francesco](https://wordpress.org/support/users/francesco_5005/)
 * Last activity: [12 years, 4 months ago](https://wordpress.org/support/topic/format-date/#post-4293480)
 * Status: resolved