Title: Use dateformat outside the function
Last modified: August 31, 2016

---

# Use dateformat outside the function

 *  Resolved [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/use-dateformat-outside-the-function/)
 * Hi again,
 * After hours of trying another issue.
 * I’m building a date format switch using [this](http://www.renegadetechconsulting.com/tutorials/jquery-datepicker-and-wordpress-i18n)
   tutorial.
 * I have changed the converter to change the php-dateformat into js-dateformat:
 *     ```
       // set datepicker date formats for europe and us
       function datepicker_dateformat($output) {
       	if ($output == 'j F Y' || $output == 'd/m/Y') {
       		$output = 'dd-mm-yy';
       	} else {
       		$output = 'yy-mm-dd';
       	}
       	return $output;
       }
       ```
   
 * Question, how do I retrieve the $output for use as dateformat in the value of
   my date input field?
 *     ```
       value="<?php echo date_i18n( get_option( 'date_format' ), esc_attr( $event_date ) ); ?>"
       ```
   
 * I know I have to replace the date_format part, but what should I add here?
 * Guido

Viewing 1 replies (of 1 total)

 *  Thread Starter [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/use-dateformat-outside-the-function/#post-6973595)
 * Yes, did found it myself.
 * Don’t use the function for this.
    Create this to set the same dateformat for 
   value:
 *     ```
       // set datepicker date formats for europe and us
       $output = get_option( 'date_format' );
       if ($output == 'j F Y' || $output == 'd/m/Y') {
       	$output = 'd-m-Y';
       } else {
       	$output = 'Y-m-d';
       }
   
       // the date input field value
       value="<?php echo date_i18n( $output , esc_attr( $event_date ) ); ?>"
       ```
   
 * Resolved 🙂
 * Guido

Viewing 1 replies (of 1 total)

The topic ‘Use dateformat outside the function’ is closed to new replies.

## Tags

 * [dateformat](https://wordpress.org/support/topic-tag/dateformat/)
 * [datepicker](https://wordpress.org/support/topic-tag/datepicker/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 1 participant
 * Last reply from: [Guido](https://wordpress.org/support/users/guido07111975/)
 * Last activity: [10 years, 4 months ago](https://wordpress.org/support/topic/use-dateformat-outside-the-function/#post-6973595)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
