Sunday, June 27

Group by date time in MySql

I create a field with date-time option like this

`scan_date` datetime DEFAULT NULL,


And I just know that we can grab date only partial by using date in sql statement. Try this:

SELECT avg(wqi), date(scan_date) dateOnly FROM `riverdata` group by dateOnly


:P

Monday, June 14

Highchart JS: Setting up PHP timezone

I have a problem when converting date-time store in MySQL (in this format (Y-m-d H:i:s)) to unix timestamp by using strtotime

The server that i used to host set the date_default_timezone_set to "Asia/Kuala_Lumpur" and i notice when capturing current time, the output will display 1 day backdate.

To solve this, you must set the time zone to

date_default_timezone_set('Etc/GMT+12');

Enjoy:)