Okay
  Public Ticket #3382993
Date format ('d/m/y')
Closed

Comments

  •  1
    Zeba Lyra started the conversation

    wpDataTables has several options of Date format in the Settings.

    But none of them is: 'd/m/y'
    For example: 31/05/23 (d/m/y)

    - How can I be able to set the Date format ('d/m/y') in the Settings?

    I am currently using this Workaround Code.
    But with a higher processing cost due to the function requires scanning all column(s) lines.

    I look forward to an answer.

    Regards,

    <?php
    /**
     * Filter and format the cell value by column name.
     *
     * @param string $formattedValue The cell value.
     * @param int    $tableId       The ID of the table.
     * @param string $columnHeader  The name of the column.
     *
     * @return string The formatted cell value.
     */
    function wpdatatables_filter_cell_by_column_name($formattedValue, $tableId , $columnHeader) { 
        // If the column name does not contain the string 'date', return the original value.
        if (strpos($columnHeader, 'date') === false) { 
            return $formattedValue;
        } 
        // If the column name contains 'date', format the cell value.
        $date = DateTime::createFromFormat('d/m/Y', $formattedValue);
        // If the value is not a valid date, return the original value.
        if ($date === false) {
            return $formattedValue;
        }
        // If the value is a valid date, return it in the 'd/m/y' format.
        return $date->format('d/m/y');
    }
    add_filter('wpdatatables_filter_cell_output', 'wpdatatables_filter_cell_by_column_name', 10, 3);
  •  1,848
    Miloš replied


    Hi, Zeba.

    You are right, at the moment we do not have this particular Date format, as (d/m/y),

    the only one similar to that is with the dots separators, like (d.m.y) , for example  '31.05.23'.

    9966191011.png

    If you wish to see this format added as built-in option soon, you can make a development suggestion and we will do our best to add it as soon as possible.

    Please feel free to search on our suggestions page

     to see if someone may be already suggested this feature. If you can't see it, feel free to add your suggestion there,  and as more people vote, the feature will move higher on the priority list.

    You can certainly follow our changeLog page if you'd like ( it is also available in the plugin dashboard), where we state any changes/new features/bug fixes during updates;

    and our newsletter, so you're informed about new features, bug fixes, freebies, etc.

    -

    Unfortunately, at this time, we do not have a workaround example, we haven't tried something like that yet,

    so a custom solution would be needed, which is not covered by our support.


    Thank you for sharing your workaround code with us, we will pass it to our developers, it should help them to save some time when they start working on adding this Date Format to our plugin.

    We can't promise an exact ETA when they will start working on this, but as mentioned, you can keep a lookout on our ChangeLog.


    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  •  1
    Zeba Lyra replied

    I thought it would be simpler. It is hardly simpler.

    And as a non-expert in coding, besides strongly hope for this to happen, I can share this 'budget-friendly' workaround:

    (Any suggestions to improve are welcome)

    <?php
    /**
     * Filter and format the cell value by column name.
     *
     * @param string $formattedValue The cell value.
     * @param int    $tableId       The ID of the table.
     * @param string $columnHeader  The name of the column.
     *
     * @return string The formatted cell value.
     */
    function wpdatatables_filter_cell_by_column_name($formattedValue, $tableId , $columnHeader) { 
        // If the column name does not contain the string 'date', return the original value.
        if (strpos($columnHeader, 'date') === false) { 
            return $formattedValue;
        } 
        // If the column name contains 'date', format the cell value.
        $date = DateTime::createFromFormat('d/m/y', $formattedValue);
        // If the value is not a valid date, return the original value.
        if ($date === false) {
            return $formattedValue;
        }
        // If the value is a valid date, return it in the 'd/m/y' format.
        return $date->format('d/m/y');
    }
    add_filter('wpdatatables_filter_cell_output', 'wpdatatables_filter_cell_by_column_name', 10, 3);
  •  1,848
    Miloš replied

    Hi, Zeba.

    Apologies for the waiting time.

    Thank you for sharing this workaround with us, I will pass it to our developers.

    They will take a closer look and we will see if we might have any improvement advice at this time, or at least I am sure that it can help them for a future improvement on our end.

    As soon as they advise, we will report back.

    Thank you for your patience, as always.

    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  •  1,848
    Miloš replied

    Hi, Zeba.

    We have been advised by our devs.

    Unfortunately, using a specific Date Format in our Plugin affects many factors of the plugin's functionalities,

    such as filtering, sorting and other logic, so until our developers add this new Date Format, sadly it is not possible to add it with any workaround while maintaining "normal" functionality of our plugin.

    Of course, you can still try any custom workaround if you find any, but we advise caution,

    since it is going to affect a lot of factors, as mentioned.

    I hope that helps at least as an explanation, and our devs will do their best to add this new Format as soon as possible.

    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  •  1
    Zeba Lyra replied

    Thanks for the explanation.

    I shall take double caution.

    Of course, I'll keep venturing into trying  improve the workaround too.

    But aware that it is a paleactive solution.
    I mean, until the devs add this new Date Format.

    I think it would be a great (apparently) 'not-so-hard-effort' item to add to the next update changelog.
    ('casually mentioning' to Product Manager)

    Just a suggestion from someone who greatly appreciates the work of wpDataTable's team.

    Best Regards,

  •  1,848
    Miloš replied

    Hi, Zeba.

    You're welcome, no problem at all.

    Understood.

    Of course, i spoke with our developers and will do my best to 'push' the priority on adding this,

    i hope that it should not pose, as you said, too much effort to implement it as soon as possible.smile.png

    Thanks for the suggestion, as always,

    and as you know - please don't hesitate to create other tickets if anything else comes up in the meantime

    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables