Home Forums Chart Support How to Change date format for PHP Reply To: How to Change date format for PHP



CanvasJS is a JavaScript based charting library which accept date-time in JavaScript date formats only. In your case, you will have to convert PHP date to JavaScript date to make it work fine. To achieve that, first you need to convert PHP date to PHP timestamp using strtotime. As PHP timestamp is in seconds and JavaScript timestamp is in milliseconds, you will have to multiply PHP timestamp by 1000. After converting it to JavaScript timestamp, you can pass it to chart data along with setting xValueType to ‘dateTime’. Please find the code-snippet below for converting PHP date to JavaScript timestamp.

$phpTimestamp = strtotime("2020-03-05");
$javaScriptTimestamp = $phpTimestamp * 1000;

Chart with timestamp data in x-axis

Vishwas R
Team CanvasJS