Jump to content


Format date in column using callbackColumn


  • Please log in to reply
10 replies to this topic

#1 Marty

Marty

    Member

  • Members
  • PipPip
  • 11 posts

Posted 20 September 2017 - 12:37 PM

I'd like to view the date columns as: 2017-09-20 14:00:00. 

 

$crud->callbackColumn(
'event_datetime', function ($value, $row) {
return date('Y-m-d H:i:s', strtotime($value));
}
);

 

But date is still shown as: 20-09-2017 2:00:00 PM

 

GorceryCRUD Enterprise version 2.3.3

 



#2 Marty

Marty

    Member

  • Members
  • PipPip
  • 11 posts

Posted 22 September 2017 - 07:11 AM

I'm also unable to use the Quick Search when DateTime is used in the column.

Tried to fill in the default data format and variations, all return zero rows..

 

Please confirm if this is a bug, as for not being able to change date (time) format with callbackColumn.

 

Thank you in advance.



#3 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,151 posts
  • LocationLondon

Posted 25 September 2017 - 11:22 AM

Hello Marty,
 
Grocery CRUD Enterprise is using dates with a different way from Community Edition. We are getting lot of requests for the date changes as this change wasn't documented. The main difference is that the date is transformed into the local time format and language. We will give you an example to be more clear.
 
If the person is using your project from USA (and the laptop is configured with USA local time), the date will translated from: 2017-08-20 to 08/20/2017 and the language will be in English. If the person is using the web application from Greece (or change the settings to Greek settings) the date will be transformed as: 20/08/2017 and the translation will be in Greek. The main reason that we did that is in order to avoid common date issues like format, lang strings... e.t.c. that we had with community edition.
 
The above feature may not seem that obvious on browsers but on mobile devices it is really helpful as the user can input the date with the calendar of their mobile and see the date as they configured it in their mobile phone.
 
Now although this new feature took extra effort from us to create it (we could just copy the date functionality from community really) we are getting lot of requests from developers that they want the old way of adding dates. Same for all the browsers and same for all the devices. As we still believe that the local time format is the best, we have it in our backlog to add <strong>the option</strong> to the developer to use the older functionality the dates (date format/language will be unique to everyone)
 
If you are interested to this functionality please let me know by sending me an email at info@grocerycrud.com so I can inform you once this functionality is available.
 
Until then for your request a work-around for your needs (to have the sql date everywhere):
 
1. Open with your editor the file: /grocery-crud/js/build/grocery-crud-v2.3.3.fb12568.js and at around line 9260 you will see a function getFormatter that will look like this:
    getFormatter: function getFormatter() {
        if (this.dateFormatter === null) {

            if (typeof Intl !== 'undefined') {
                this.dateFormatter = new Intl.DateTimeFormat(DateAndTime.getLocale());
            } else {
                this.dateFormatter = {
                    format: function format(myDate) {
                        return myDate.toLocaleDateString();
                    }
                };
            }
        }

        return this.dateFormatter;
    },

2. Change the above function to the following:

 

getFormatter: function getFormatter() {
    if (this.dateFormatter === null) {
        this.dateFormatter = {
            format: function format(myDate) {
                // sql date
                return myDate.toISOString().slice(0, 10);
            }
        };
    }
    return this.dateFormatter;
},

With these two steps you will see that the date format will be the sql date as requested into your datagrid.

 

Regards

Johnny


Posted Image

#4 Marty

Marty

    Member

  • Members
  • PipPip
  • 11 posts

Posted 28 September 2017 - 09:33 AM

Hi Johnny,

 

Thank you very much for the comprehensive response, all clear now. Though in my opinion the developer should have the possibility to choose how to implement a date format.

 

In addition to the Date column format, my current format is for example shown as "23-9-2017 10:15:00 AM".

The Quick search will only return rows for digits, i.e. 23 or 9 or 2017.

Typing 23-9 or 9-2017 or AM returns no rows.



#5 Marty

Marty

    Member

  • Members
  • PipPip
  • 11 posts

Posted 06 October 2017 - 12:35 PM

Regarding the suggested code change, with GCE v 2.3.4,  
it will not work as expected in Safari.
 
getFormatter: function getFormatter() {
    if (this.dateFormatter === null) {
        this.dateFormatter = {
            format: function format(myDate) {
                // sql date
                return myDate.toISOString().slice(0, 10);
            }
        };
    }
    return this.dateFormatter;
},
 
Safari 11.0 (12604.1.38.1.7) will show empty fields or I should say the field is not rendered because Quick search works.
 
On Chrome 60.0.3112.113 date time column shows, 2017-10-01 12:00:00 AM
so time is not in 24h format.  
 
Firefox 56.0 will show expected result, 2017-10-01 00:00:00
And Quick search behaves as expected.

 



#6 cletourneau

cletourneau

    Member

  • Members
  • PipPip
  • 15 posts
  • LocationMontreal

Posted 06 October 2017 - 03:24 PM

Even though I don't agree with the decision (developer should be allowed to force the date format, in multiple case that is mandatory), the behaviour explained by John is acceptable for me.

Problem is, in my case, the library doesn't behave like John describes.

 

As you can see in the following screenshot, the dates from the edit dialogs are different than the one displayed in the columns.

 

Attached Thumbnails

  • Screen Shot 2017-10-06 at 11.14.34 AM.png


#7 cletourneau

cletourneau

    Member

  • Members
  • PipPip
  • 15 posts
  • LocationMontreal

Posted 06 October 2017 - 04:06 PM

Also, as you can see in the following screenshots, the date typed by the user is 1 day different than the one displayed. In the database, the date is the one typed by the user.

 

 

Attached Thumbnails

  • Screen Shot 2017-10-06 at 12.04.29 PM.png
  • Screen Shot 2017-10-06 at 12.04.40 PM.png


#8 ncasolajimenez

ncasolajimenez

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 17 October 2017 - 01:46 PM

 

Hello Marty,
 
Grocery CRUD Enterprise is using dates with a different way from Community Edition. We are getting lot of requests for the date changes as this change wasn't documented. The main difference is that the date is transformed into the local time format and language. We will give you an example to be more clear.
 
If the person is using your project from USA (and the laptop is configured with USA local time), the date will translated from: 2017-08-20 to 08/20/2017 and the language will be in English. If the person is using the web application from Greece (or change the settings to Greek settings) the date will be transformed as: 20/08/2017 and the translation will be in Greek. The main reason that we did that is in order to avoid common date issues like format, lang strings... e.t.c. that we had with community edition.
 
The above feature may not seem that obvious on browsers but on mobile devices it is really helpful as the user can input the date with the calendar of their mobile and see the date as they configured it in their mobile phone.
 
Now although this new feature took extra effort from us to create it (we could just copy the date functionality from community really) we are getting lot of requests from developers that they want the old way of adding dates. Same for all the browsers and same for all the devices. As we still believe that the local time format is the best, we have it in our backlog to add <strong>the option</strong> to the developer to use the older functionality the dates (date format/language will be unique to everyone)
 
If you are interested to this functionality please let me know by sending me an email at info@grocerycrud.com so I can inform you once this functionality is available.
 
Until then for your request a work-around for your needs (to have the sql date everywhere):
 
1. Open with your editor the file: /grocery-crud/js/build/grocery-crud-v2.3.3.fb12568.js and at around line 9260 you will see a function getFormatter that will look like this:
    getFormatter: function getFormatter() {
        if (this.dateFormatter === null) {

            if (typeof Intl !== 'undefined') {
                this.dateFormatter = new Intl.DateTimeFormat(DateAndTime.getLocale());
            } else {
                this.dateFormatter = {
                    format: function format(myDate) {
                        return myDate.toLocaleDateString();
                    }
                };
            }
        }

        return this.dateFormatter;
    },

2. Change the above function to the following:

getFormatter: function getFormatter() {
    if (this.dateFormatter === null) {
        this.dateFormatter = {
            format: function format(myDate) {
                // sql date
                return myDate.toISOString().slice(0, 10);
            }
        };
    }
    return this.dateFormatter;
},

With these two steps you will see that the date format will be the sql date as requested into your datagrid.

 

Regards

Johnny

 

 

Hi, and there is a way to force the date format? For example i'm using PHP desktop, so probably GC think my language is English, and i want to show it in spanish. Thanks!



#9 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,151 posts
  • LocationLondon

Posted 17 October 2017 - 09:15 PM

Hello guys,

 

As I am getting lot of questions for the date and datetime I did create a topic that I hope I am answering all of your questions. The URL is here: https://www.groceryc...atetime-fields/


Posted Image

#10 mjuliand

mjuliand

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 18 November 2018 - 04:49 PM

Hard way to do it:

 

Edit Grocery_CRUD.php in libraries folder

 

about in line 295 change this:

list($hours,$minutes) = explode(":",substr($value,11));
$value = date($this->php_date_format." - H:i", mktime ((int)$hours , (int)$minutes , 0, (int)$month , (int)$day ,(int)$year));

to this:

list($hours,$minutes,$seconds) = explode(":",substr($value,11));
$value = date($this->php_date_format." - H:i:s", mktime ((int)$hours , (int)$minutes , (int)$seconds, (int)$month , (int)$day ,(int)$year));


#11 rkrajnik

rkrajnik

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 26 July 2020 - 07:55 PM

Johnny knows his team needs to fully fix their date/time storage and display date-related code.  It's way too confusing (most of my apps are date-sensitive, I just assumed that GCE would handle date formats normally.)  Johnny needs to listen a bit more to his customers and not an "industry" that he seems to think he needs to follow.  I expect this to get better , Johnny is a good man! 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users