Hi,

I wish to change the default date format for an exposed Date filter YYYY-MM-DD to reflect my site setup DD/MM/YYYY

In views for the fields I have assigned the format to be the site default short format and this displays perfectly.

However I have an exposed filter block with the ui.datepicker popup calendar enabled on the date filters, the format is YYYY-MM-DD for this and I have no idea how to change it to what I need.

Thanks,
Gary

CommentFileSizeAuthor
#12 views_filter_date_popup.tar_.gz767 bytesenboig

Comments

merlinofchaos’s picture

Status: Active » Fixed

The input format for the exposed date filters is anything that can be read by strtotime(), so mm/dd/yyyy should work just fine with no changes.

enboig’s picture

Status: Fixed » Active

I have the same problem, I need date filter to be able to handle DD/MM/YYYY, not MM/DD/YYYY; I think a way of doing this would be a field when defining the date filter where you could customise the input with something like "[day]/[month]/[year]".
It would be useful then to be able to add a description line telling what date format does the filter expect.

merlinofchaos’s picture

Status: Active » Fixed

Sorry, what you get is what strtotime() supports. If it doesn't support that format, then you don't get it.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

garyh’s picture

Status: Closed (fixed) » Active

Hi,

I don't understand fully. I want to change the format to DD/MM/YYYY, under my date field it automatically set to:
Format: 2009-06-25

I want this default to always read
Format: 25-06-2009

It must be DD/MM not MM/DD.

Thanks,
Gary

garyh’s picture

Status: Active » Closed (fixed)

Hi,

The problem is actually a limitation of the Date module, see: http://drupal.org/node/444022

Thanks for the feedback here anyhow.

Thanks,
Gary

enboig’s picture

I don't agree about this being a limitation of Date. I think it would be 'easy' to add options to configure 'views date filter' so you could select arguments order:
- day month year
- month day year
- year month day
- ....
Anything which isn't 'numeric' could be treated as a separator; so it would be possible using mktime() to "reorder" the date.

If actual arguments is left as 'default' I don't think anything will break.

I don't know anything about filters right now, but as I am interested in this functionallity, with some help I will try it and test it.

cimo’s picture

Subscribing, this input format looks weird for a normal user..

sirpy’s picture

I've encountered the same problem, a simple solution requires to hard code the format in the code.

in the date_api_filter_handler, in the function date_parts_form, enter whatever format you want in the $format variable.
when the date is parsed back the date api can parse almost any format automaticly, so you should be fine.

enboig’s picture

Status: Closed (fixed) » Active

In PHP 5.3 there is a function called "date_parse_from_format()" which is similar to strtotime() but allows you to define custom format. I have ported it to PHP (it can be improved a lot). Right now I need to:
1. Include "date_parse_from_format()" definition (just if needed) in some module (maybe date_api?).
2. Add an option in views date filter to define date format according to date() function
3. Change views to use date_parse_from_format() and not strtotime() if date format is defined

My version of date_parse_from_format is:

if (!function_exists('date_parse_from_format')) {
  function date_parse_from_format($format, $date) {
    $i=0;
    $pos=0;
    $output=array();
    while ($i< strlen($format)) {
      $pat = substr($format, $i, 1);
      $i++;
      switch ($pat) {
        case 'd': //	Day of the month, 2 digits with leading zeros	01 to 31
          $output['day'] = (int)substr($date, $pos, 2);
          $pos+=2;
        break;
        case 'D': // A textual representation of a day: three letters	Mon through Sun
          //TODO
        break;
        case 'j': //	Day of the month without leading zeros	1 to 31
          $output['day'] = substr($date, $pos, 2);
          if (!is_numeric($output['day']) || ($output['day']>31)) {
            $output['day'] = substr($date, $pos, 1);
            $pos--;
          }
          $pos+=2;
        break;
        case 'm': //	Numeric representation of a month: with leading zeros	01 through 12
          $output['month'] = (int)substr($date, $pos, 2);
          $pos+=2;
        break;
        case 'n': //	Numeric representation of a month: without leading zeros	1 through 12
          $output['month'] = substr($date, $pos, 2);
          if (!is_numeric($output['month']) || ($output['month']>12)) {
            $output['month'] = substr($date, $pos, 1);
            $pos--;
          }
          $pos+=2;
        break;
        case 'Y': //	A full numeric representation of a year: 4 digits	Examples: 1999 or 2003
          $output['year'] = (int)substr($date, $pos, 4);
          $pos+=4;
        break;
        case 'y': //	A two digit representation of a year	Examples: 99 or 03
          $output['year'] = (int)substr($date, $pos, 2);
          $pos+=2;
        break;
        case 'g': //	12-hour format of an hour without leading zeros	1 through 12
          $output['hour'] = substr($date, $pos, 2);
          if (!is_numeric($output['day']) || ($output['hour']>12)) {
            $output['hour'] = substr($date, $pos, 1);
            $pos--;
          }
          $pos+=2;
        break;
        case 'G': //	24-hour format of an hour without leading zeros	0 through 23
          $output['hour'] = substr($date, $pos, 2);
          if (!is_numeric($output['day']) || ($output['hour']>23)) {
            $output['hour'] = substr($date, $pos, 1);
            $pos--;
          }
          $pos+=2;
        break;
        case 'h': //	12-hour format of an hour with leading zeros	01 through 12
          $output['hour'] = (int)substr($date, $pos, 2);
          $pos+=2;
        break;
        case 'H': //	24-hour format of an hour with leading zeros	00 through 23
          $output['hour'] = (int)substr($date, $pos, 2);
          $pos+=2;
        break;
        case 'i': //	Minutes with leading zeros	00 to 59
          $output['minute'] = (int)substr($date, $pos, 2);
          $pos+=2;
        break;
        case 's': //	Seconds: with leading zeros	00 through 59
          $output['second'] = (int)substr($date, $pos, 2);
          $pos+=2;
        break;
        case 'l': // (lowercase 'L')	A full textual representation of the day of the week	Sunday through Saturday
        case 'N': //	ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0)	1 (for Monday) through 7 (for Sunday)
        case 'S': //	English ordinal suffix for the day of the month: 2 characters	st: nd: rd or th. Works well with j
        case 'w': //	Numeric representation of the day of the week	0 (for Sunday) through 6 (for Saturday)
        case 'z': //	The day of the year (starting from 0)	0 through 365
        case 'W': //	ISO-8601 week number of year: weeks starting on Monday (added in PHP 4.1.0)	Example: 42 (the 42nd week in the year)
        case 'F': //	A full textual representation of a month: such as January or March	January through December
        case 'u': //	Microseconds (added in PHP 5.2.2)	Example: 654321
        case 't': //	Number of days in the given month	28 through 31
        case 'L': //	Whether it's a leap year	1 if it is a leap year: 0 otherwise.
        case 'o': //	ISO-8601 year number. This has the same value as Y: except that if the ISO week number (W) belongs to the previous or next year: that year is used instead. (added in PHP 5.1.0)	Examples: 1999 or 2003
        case 'e': //	Timezone identifier (added in PHP 5.1.0)	Examples: UTC: GMT: Atlantic/Azores
        case 'I': // (capital i)	Whether or not the date is in daylight saving time	1 if Daylight Saving Time: 0 otherwise.
        case 'O': //	Difference to Greenwich time (GMT) in hours	Example: +0200
        case 'P': //	Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3)	Example: +02:00
        case 'T': //	Timezone abbreviation	Examples: EST: MDT ...
        case 'Z': //	Timezone offset in seconds. The offset for timezones west of UTC is always negative: and for those east of UTC is always positive.	-43200 through 50400
        case 'a': //	Lowercase Ante meridiem and Post meridiem	am or pm
        case 'A': //	Uppercase Ante meridiem and Post meridiem	AM or PM
        case 'B': //	Swatch Internet time	000 through 999
        case 'M': //	A short textual representation of a month: three letters	Jan through Dec
        default:
          $pos++;
      }
    }
    return  $output;
  }
}

dawehner’s picture

Project: Views (for Drupal 7) » Date
Version: 6.x-2.5 » 6.x-2.x-dev
Component: exposed filters » Views Filter

That's probably a feature for the date module, so move the module.

enboig’s picture

StatusFileSize
new767 bytes

I just created a module using hook_form_alter() to add options to views date filter to choose date format. It also uses date_popup to choose date.

Any comment/fix wellcome

enboig’s picture

I just posted a new version at #502824: Date format in exposed filter (views); now it support between operator.

damienmckenna’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

We're sorry but the D6 release of Date module is no longer being supported. You are encouraged to update to Drupal 7 or 8, or direct questions to Drupal Answers.