• Resolved timhuk

    (@timhuk)


    Hi,

    Is there a way to format the date display differently?

    I have 2 dates shown in my upload data: the upload date and an additional/custom data field that uses the “date” type. Each of these are displayed in a different format.

    Upload date shows (for example): 24th February 2017
    Additional data shows (for example):2017-02-24

    Is it possible to format these to show the same date format (ideally dd_mmm_yyyy)

    Many thanks for any help

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author nickboss

    (@nickboss)

    Hi, this is not so simple because both formats are treated differently. Here are instructions:

    1. You need to set the format of the custom data field (from the visual editor) to: (dd_M_yy)
    2. You need to put the following code isnide the page of the file viewer, right below the shortcode (in order to re-format the upload date):

    
    <script type="text/javascript">
    var scr = document.createElement("SCRIPT");
    scr.type = "text/javascript";
    scr.src = "https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js";
    document.body.appendChild(scr);
    wfu_tweak_browser_convert_date = function(bid) {
    	var dates = document.querySelectorAll(".wfu_browser-" + bid + " span.wfu_display_date");
    	var datadates = document.querySelectorAll(".wfu_browser-" + bid + " input.wfu_data_date");
    	var unix = document.querySelectorAll(".wfu_browser-" + bid + " input.wfu_data_date_sort");
    	for (var i = 0; i < dates.length; i++) {
    		var dtstr = moment.unix(unix[i].value).format("DD_MMM_YYYY");
    		dates[i].innerHTML = dtstr;
    		datadates[i].value = dtstr;
    	}
    }
    if (!window["wfu_browser_update_html_orig"]) {
    	window["wfu_browser_update_html_orig"] = wfu_browser_update_html;
    	wfu_browser_update_html = function(bid, html) {
    		window["wfu_browser_update_html_orig"](bid, html);
    		wfu_tweak_browser_convert_date(bid);
    	}
    }
    wfu_addEventHandler(window, "load", function() { wfu_tweak_browser_convert_date(1); });
    </script>
    

    Test it and let me know.

    Nickolas

    Thread Starter timhuk

    (@timhuk)

    Great information. Works perfectly.

    Many thanks Nickolas!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Different Date Formats’ is closed to new replies.