How to convert MySQL datetime value to google api datetime table
I am trying to convert a value from a datetime field in a MySQL database to a value that I can pass to a google time datetime field.
For example, the value of the MySQL: 2012-03-05 17:03:56
.
Google Chart Api Link: http://code.google.com/apis/chart/interactive/docs/gallery/linechart.html
I want to pass this to a column defined like this: data.addColumn('datetime', 't');
I want to send it to a string as such: data.addRow([date_value]);
I'm not sure how to convert between them. So what I'm asking is How to convert MySQL datetime value to datetime api value in google chart?
source to share
Google just uses the standard javascript Date object. The easiest would be to get unix_timestamp(yourdatefield)
from MySQL which gives you the seconds-s-epoch.
The Javascript date object takes milliseconds-per-epoch as one initializer value, so:
data.addRow(new Date(<?php echo ($seconds_from_db) ?>000));
^^^--- 3 extra zeroes to make it a millisecond value
source to share