Extra field date format

Discussion in 'Templates, HTML, CSS, and Design Help' started by metrony, Mar 6, 2011.

  1. metrony Customer

    Does anyone know where you can modify the format of a 'Date Type' extra field? It's currently formatted as yyyy-mm-dd. I thought it would be controlled by the regional settings but it appears to be separate from that.

    Thanks in advance.
  2. John Snyder Staff

    I'm afraid this is a global setting done via the date_input jquery plugin. You can change it but it will affect all date fields that use the date picker.

    javascript/jquery/date_input/jquery.date_input.min.js:
    Code:
    $.extend(DateInput.DEFAULT_OPTS, {
      stringToDate: function(string) {
        var matches;
        if (matches = string.match(/^(\d{4,4})-(\d{2,2})-(\d{2,2})$/)) {
          return new Date(matches[1], matches[2] - 1, matches[3]);
        } else {
          return null;
        };
      },
      dateToString: function(date) {
        var month = (date.getMonth() + 1).toString();
        var dom = date.getDate().toString();
        if (month.length == 1) month = "0" + month;
        if (dom.length == 1) dom = "0" + dom;
        return date.getFullYear() + "-" + month + "-" + dom;
      }
    });
    
    This could have some unforseen impact on listings expiration set via admin or etc. I'd be sure to test carefully if you decide to change this value.

    You can change it only for listings but I'm not sure if its only a 1 place edit. Look in includes/classes/kernel/Listings.php You can attempt to do the javascript above when the field is built.

    Find:
    PHP:

    //birthdate or date field
     
    $optdata.='<script language="javascript" type="text/javascript">
                            $(function() {
                                   // you can attempt to override again here like in the jquery.date_input.min.js file
                                   $("#opt'
    .$row['fID'].'").date_input();
                             });
                        </script>'
    ;
    You can see more about the jquery plugin here: jQuery Date Input: Jon Leighton
  3. metrony Customer

    I don't use the field that often so I probably won't make the change. But thanks for letting me know where the changes need to be made.

Share This Page