I've linked Google data studio with a MySQL database using the standard connector. Almost everything works fine except for date and datetime fields.
I have these 2 fields in phpmyadmin (field name, field type, output
):
2017-09-27 12:31:04
2017-12-24
In Data Studio I've set these types, but none of them are recognised:
I tried to format the field with date_format in my SELECT:
DATE_FORMAT(p.Expiration_date, '%Y%m%d') AS "Expiration Date"
I even tried other date_formats but they're never recognised as dates in Data Studio:
DATE_FORMAT(p.Expiration_date, '%Y/%m/%d') AS "Expiration Date"
DATE_FORMAT(p.Expiration_date, '%Y-%m-%d') AS "Expiration Date"
Any idea?
A Looker Studio data source can connect to a single MySQL database table. The Looker Studio MySQL connector is based on Google Cloud SQL for MySQL, and is subject to the same limits on versions and supported features. Learn more about Google Cloud SQL for MySQL.
MySQL retrieves and displays DATETIME values in ' YYYY-MM-DD hh:mm:ss ' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59' . The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.
Introduction to MySQL DATE data type MySQL uses yyyy-mm-dd format for storing a date value. This format is fixed and it is not possible to change it.
The date_format() function is used to get the date in specified format. The datediff() function is used to get the difference between the two specified date values. The day() function is used to get the day from the given date. The dayname() function is used to get the name of the day from the given date.
I had the same issue. My approach to solve this is to modify the date format within Google Data Studio by creating a new dimension, reformatting the mySQL Datetime into the desired format.
In your example you use DATE_FORMAT. I wonder if you apply this in Data Studio (which does not know DATE_FORMAT) or in mySQL?. If you do it in data studio and leave your mySQL/phpmyadmin untouched you can use this:
TODATE(your-date-field, 'DEFAULT_DASH', '%Y%m%d')
This will take the date format YYYY-MM-DD with optional time in HH:ii:ss and reformat it into YYYYMMDD which works with data studio.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With