Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL date and datetime formats unrecognised by Data Studio

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):

  • Validated_date datetime 2017-09-27 12:31:04
  • Expiration_date date 2017-12-24

In Data Studio I've set these types, but none of them are recognised:

  • Validated_date Date Hour (YYYYMMDDHH)
  • Expiration_date Date (YYYYMMDD)

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?

like image 456
Alex Mille Avatar asked Nov 18 '17 11:11

Alex Mille


People also ask

Can Data Studio connect to MySQL?

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.

What format is datetime in 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.

What is the fix format of date statement in MySQL?

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.

Is date function in MySQL?

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.


1 Answers

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.

like image 197
Gegenwind Avatar answered Sep 28 '22 12:09

Gegenwind