Jump to content


read state doesn't use the configured date format

date datetime read state config

  • Please log in to reply
1 reply to this topic

#1 Carlos Castell

Carlos Castell

    Newbie

  • Members
  • Pip
  • 4 posts
  • LocationGuatemala

Posted 07 April 2015 - 09:32 PM

Hi,

 

I have configured a date format in the grocery_crud.php config file:

$config['grocery_crud_default_date_format']  = 'd M Y';

This is working fine for the "list" state (table view), however it is not the case for the "read" state, it keeps looking as "yyy-mm-dd". 

 

 

Am I missing something?

 

 

Btw, I am using datatables.

Attached Thumbnails

  • Untitled.png
  • img2.png


#2 Carlos Castell

Carlos Castell

    Newbie

  • Members
  • Pip
  • 4 posts
  • LocationGuatemala

Posted 08 April 2015 - 09:47 PM

I have assumed that the read state will never format the date so I decided to do it myself by modifying the read.php file under assets\grocery_crud\themes\datatables\views.

 

You just need to add the below code in the div that prints the values out, around line 34.

 

Before the change:

<div class='form-input-box' id="<?php echo $field->field_name; ?>_input_box">
<?php echo $input_fields[$field->field_name]->input?>

After the change:

				<div class='form-input-box' id="<?php echo $field->field_name; ?>_input_box">
					<?php 
						$res = preg_match('/[0-9]{4}\-[0-9]{2}\-[0-9]{2}/',$input_fields[$field->field_name]->input,$var);
						if($res==1) {
							if(!preg_match('/0000/',$var[0])) {
								$ci = &get_instance();
								$dt = new DateTime($var[0]);
								$output = $dt->format($ci->config->item('grocery_crud_default_date_format'));
								$res = preg_match('/[0-9]{4}\-[0-9]{2}\-[0-9]{2}\s[0-2][0-9]\:[0-6][0-9]/',$input_fields[$field->field_name]->input,$var);
								if($res==1) {
									$dt = new DateTime($var[0]);
									$output = $dt->format($ci->config->item('grocery_crud_default_datetime_format'));
								}
								echo $output;
							} else 
								echo "";
						} else
							echo $input_fields[$field->field_name]->input?>

Now you can test the date format in the read state... and make sure you have defined the format you want in the application/config/grocery_crud.php file, I used:

 

$config['grocery_crud_default_date_format']  = 'd M Y';

$config['grocery_crud_default_datetime_format'] = 'd M Y - H:i';

 

Cheers!







Also tagged with one or more of these keywords: date, datetime, read, state, config

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users