• Resolved jansvrs

    (@jansvrs)


    Hi Doeke,

    Love the plugin!

    I’m trying to change the date format in CSV exports to Y-m-d.

    I’m doing this:

    add_filter('gfexcel_field_date_format', function($format) {
        return 'Y-m-d';
    });

    But it seems it’s irrelevant what I write as my custom format. In the export it always shows up as m/d/Y as soon as I add the filter to the functions.php. If I don’t add the snippet, the dates in my export are formatted as d.m.Y

    Any idea what I’m doing wrong?

    Thanks
    Jan

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Doeke Norg

    (@doekenorg)

    Hi Jan,

    Is it an actual date field, or do you want to format the created date? Because that is a meta field.

    Thread Starter jansvrs

    (@jansvrs)

    Wowow quick reply! Thank you!

    It’s two actual date fields. We are asking for date of birth and when someone can start a new job.

    We also have dates in text fields that we pass through parameters. They are also formatted as m.d.Y. If there’s a way to also format them to Y-m-d that would be great.

    Plugin Author Doeke Norg

    (@doekenorg)

    HI Jan, there seems to be a bug in the plugin. I’ll remedy that. You actually should return something like “ymd_dash” if you want Y-m-d. The dash refers to the separator. Could also be dot. If nothing is added, like ymd it will add / as a separator.

    Best thing you can do at the moment is to the use gfexcel_field_value_date and acutally parse the date how it comes in, and turn it into what you want.

    something like:

    add_filter('gfexcel_field_value_date', function ($date) {
        try {
            return \DateTime::createFromFormat('d.m.Y', $date)->format('Y-m-d');
        } catch (\Exception $e) {
            return $date; // keep original if something goes wrong.
        }
    });

    I’ll see if I can fix the intended behavior later today.

    You can use the same code for the other fields if you know the type and id. So something like: gfexcel_field_value_text_3_13 for a text field on form 3 with the id of 13.

    • This reply was modified 3 years, 10 months ago by Doeke Norg. Reason: Info for other fields
    Thread Starter jansvrs

    (@jansvrs)

    Amazing, thank you so much! ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Format date as Y-m-d’ is closed to new replies.