Date Format

edited January 2012 in Feature Requests
any progress on this ? or we already allow to set our own date format ?

Comments

  • edited 7:26AM
    There has been some progress on this for the next version. As for the next release date, we are not quite certain at the moment... we are still actively working on it.
  • edited 7:26AM
    What do you need Knight? We have some code for d/m/y down here if that helps you and it's urgent.
  • edited 7:26AM
    ya , my client is request for d/m/y for quite some time or at least something like "Jan 3 2010", since asia country here mostly using dd mm yyyy, current setting might be quite confuse for them.
  • edited 7:26AM
    Start of in BaseFuelController: _initDatePicker function.

    Change the format strings in here to:
    dd-mm-yyyy


    Next, in MY_date_helper.php overwrite the existing function with this:

    function english_date_to_db_format($date, $hour = 0, $min = 0, $sec = 0, $ampm = 'am') { $hour = (int) $hour; $min = (int) $min; $sec = (int) $sec; if ($hour > 12) $ampm = 'pm'; if ($ampm == 'pm' and $hour < 12) { $hour += 12; } else if ($ampm == 'am' and $hour == 12) { $hour = 0; } $date_arr = preg_split('#-|/#', $date); if (count($date_arr) != 3) return 'invalid'; # Convert them all to integers foreach($date_arr as $key => $val) { $date_arr[$key] = (int) $date_arr[$key]; # Convert to integer } $new_date = ''; if (preg_match("#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})#", $date)) { if ( ! checkdate($date_arr[0], $date_arr[1], $date_arr[2])) { return 'invalid'; # Null will cause it to be ignored in validation } $new_date = $date_arr[2].'-'.$date_arr[0].'-'.$date_arr[1].' '.$hour.':'.$min.':'.$sec; } else if (preg_match("#([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})#", $date)) { if ( ! checkdate($date_arr[1], $date_arr[0], $date_arr[2])) { return 'invalid'; # Null will cause it to be ignored in validation } $new_date = $date_arr[2].'-'.$date_arr[1].'-'.$date_arr[0].' '.$hour.':'.$min.':'.$sec; } else { return 'invalid'; } $date = date("Y-m-d H:i:s", strtotime($new_date)); # normalize return $date; }

    That code is attributed to the Daylight guys, not me.

    That should be it if IIRC.

    The format of dd-mm-yyyy has to be hyphens as strtotime() can't distinguish dd/mm/yyyy from mm/dd/yyyy.
  • edited 7:26AM
    yup this is help, thanks Lance, but i think some more tweaks is required, will post back once I have it full up.
  • edited 7:26AM
    No sweat.

    I did miss one thing, the date_format in Form_builder needs to be d-m-y.

    Pretty sure _thats_ it. There was some changes in my_model::clean but I'm sure those were reversed in favor of the above.
  • edited 7:26AM
    Hi Lance, thanks this really help to solve my problem.
  • edited 7:26AM
    No worries mate. Dave did all the real work there :)
Sign In or Register to comment.