# Date field with formate DDMMYYYY -

**URL:** <https://community.gravityforms.com/t/date-field-with-formate-ddmmyyyy/5001>\
**Category:** Get Help\
**Tags:** read-only, gform\_field\_value, date-field, gform\_pre\_render, current-date\
**Created:** [June 4, 2020, 10:43am UTC](https://community.gravityforms.com/t/date-field-with-formate-ddmmyyyy/5001 "2020-06-04T10:43:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![user5e9ef5d038b36901](https://avatars.discourse-cdn.com/v4/letter/u/5daacb/32.png) [@user5e9ef5d038b36901](https://community.gravityforms.com/u/user5e9ef5d038b36901)\
**Post date:** [June 4, 2020, 10:43am UTC](https://community.gravityforms.com/t/date-field-with-formate-ddmmyyyy/5001/1 "2020-06-04T10:43:46Z")

</div>

Hi,  
I need a date field in my form that should

1. be automatically filled with the current date (today)
2. Has the format DDMMYYY, without any slashes / hyphens or other characters. e.g. 04062020
3. Is visible for the user but can not be edited.

How can I achieve that?

If this can not be done out of the box, could you post a little wordpres plugin code snipped for me?  
This is needed for a non-profit project, working with refugees - your help would be appreciated very much.  
Cheers,  
Matt

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [June 4, 2020, 3:20pm UTC](https://community.gravityforms.com/t/date-field-with-formate-ddmmyyyy/5001/2 "2020-06-04T15:20:23Z")

</div>

Hi Matt, it’s not too hard to accomplish that. First, add a single-line text field to your form. On the Appearance tab, give it a Custom CSS class name of `gf_readonly` and on the Advanced tab, check the box “allow field to be populated automatically” and add the parameter name of ‘date’.

Then add [this code](https://docs.gravityforms.com/making-a-field-read-only/#native-code-solution) to your theme functions.php file:

```auto
// update '1' to the ID of your form
add_filter( 'gform_pre_render_1', 'add_readonly_script' );
function add_readonly_script( $form ) {
    ?>
 
    <script type="text/javascript">
        jQuery(document).ready(function(){
            /* apply only to a input with a class of gf_readonly */
            jQuery("li.gf_readonly input").attr("readonly","readonly");
        });
    </script>
 
    <?php
    return $form;
}

```

Be sure to update the form ID from 1 to whatever your form ID is, or remove the \_1 from the filter if you want to have this code available on any form.

Those two steps will give you a field to hold the data, and make the input appear read only. If you want to style that readonly field, please see the advice here:

> **[How to Style Gravity Forms Read-Only Fields - Gravity Wiz](https://gravitywiz.com/how-to-style-gravity-forms-read-only-fields/)**
>
> An overview of how to style read-only and disabled fields with CSS. Includes examples of how to target specific field types and different methods of styling.

Go to the “Styling the Fields” section.

The last part is to populate the field with the date when the form is shown. You already gave the text field the parameter name of ‘date’, so you can use this filter to populate the field with a date:

> **[gform\_field\_value\_$parameter\_name - Gravity Forms Documentation](https://docs.gravityforms.com/gform_field_value_parameter_name/#populate-a-fixed-date)**
>
> This filter is executed before displaying each field and can be used to dynamically populate fields with a default value.

The actual code for you for the date format DDMMYYYY will look like this:

```auto
add_filter( 'gform_field_value_date', 'populate_the_date' );
function populate_the_date( $value ) {
	// desired format DDMMYYYY
	// ref https://www.php.net/manual/en/function.date.php
	$local_timestamp = GFCommon::get_local_timestamp( time() );
	return date_i18n( 'dmy', $local_timestamp, true );
}

```

That code can go into the theme functions.php file right near the gform\_pre\_render code you added for the readonly script.

If you have any questions, please let us know.

---

<div class="post-metadata">

**Author:** ![user5e9ef5d038b36901](https://avatars.discourse-cdn.com/v4/letter/u/5daacb/32.png) [@user5e9ef5d038b36901](https://community.gravityforms.com/u/user5e9ef5d038b36901)\
**Post date:** [June 6, 2020, 11:01pm UTC](https://community.gravityforms.com/t/date-field-with-formate-ddmmyyyy/5001/3 "2020-06-06T23:01:21Z")

</div>

Hi Chris, thanks for your help!  
Based on your code snippets I created two little WordpresPlugins that can be easily installed. For anyone who has the same or similar requirements in the future I uploaded them to GitHub:

> **[ar-ml/GravityFormsTweaks](https://github.com/ar-ml/GravityFormsTweaks)**
>
> Some Plugins for little GravityForms Tweaks (Wordpress Forms Plugin) - ar-ml/GravityFormsTweaks

Since I am not a developer, let me know if you find any mistakes.  
Cheers,  
Matt

---

<div class="post-metadata">

**Author:** ![user5e9ef5d038b36901](https://avatars.discourse-cdn.com/v4/letter/u/5daacb/32.png) [@user5e9ef5d038b36901](https://community.gravityforms.com/u/user5e9ef5d038b36901)\
**Post date:** [June 6, 2020, 11:11pm UTC](https://community.gravityforms.com/t/date-field-with-formate-ddmmyyyy/5001/4 "2020-06-06T23:11:55Z")

</div>

ah, ok I found one mistake:

```auto
$local_timestamp = GFCommon::get_local_timestamp( time() );

```

does not return my current date, but yesterdays date. I Guess this happens because of issues with the time zone. Is there an easy way how to make sure that the form users current time zone is used?  
Thanks!

---

<div class="post-metadata">

**Author:** ![richardw8k](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/richardw8k/32/2354_2.png) [@richardw8k](https://community.gravityforms.com/u/richardw8k)\
**Post date:** [January 4, 2022, 6:04pm UTC](https://community.gravityforms.com/t/date-field-with-formate-ddmmyyyy/5001/5 "2022-01-04T18:04:08Z")

</div>


