You are here:  » date format change


date format change

Submitted by marco on Tue, 2014-04-08 14:14 in

Hello,

I have added an additional 'date' productfield to the database.
One datafeed provides dates in the wrong format.
Is there a filter that could convert the date "dd.mm.yyyy" to "yyyy-mm-dd"?
For example "08.04.2014" to "2014-04-08".

Best,
Marco

Submitted by support on Tue, 2014-04-08 20:07

Hello Marco,

PHP's strtotime() function understands dd.mm.yyyyy so a simple filter using strtotime(), followed by date() would let you reformat any time format understood by strtotime() as required. Here's the code to add to includes/filter.php

  /*************************************************/
  /* strToTime */
  /*************************************************/
  $filter_names["strToTime"] = "String to Time";
  function filter_strToTimeConfigure($filter_data)
  {
    print "Format:<br />";
    print "<input type='text' size='40' name='format' value='".widget_safe($filter_data["format"])."' />";
    widget_errorGet("format");
  }
  function filter_strToTimeValidate($filter_data)
  {
    if (!$filter_data["format"])
    {
      widget_errorSet("format","required field");
    }
  }
  function filter_strToTimeExec($filter_data,$text)
  {
    return date($filter_data["format"],strtotime($text));
  }

To use, apply an instance of this filter to your `date` field for this feed, using a Format value of:

Y-m-d

For full details of date formatting available, see;
https://php.net/manual/en/function.date.php

Cheers,
David.
--
PriceTapestry.com

Submitted by marco on Thu, 2014-04-10 15:25

Hi David,

That did the job.
Thanks for the support.

Best,
Marco