Home Forums Chart Support How to Change date format for PHP

How to Change date format for PHP

Viewing 4 posts - 1 through 4 (of 4 total)
  • #28575

    Hello,
    i try to use the “PHP Spline Charts & Graphs” to show daily sales report of the month. We have a target and on daily basic i we go near the target each day of month the graph increase. But in the x value you are passing date in different format like “array(“x” => 946665000000, “y” => 3289000),” how can i convert my date into that format? please help. in PHP i have the date like “2020-03-05” so now need to convert it to that format.

    #28587

    @salman_emenacsoft,

    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

    #32502

    how with date and time like… 2020-02-17 07:25:34 i try with *1000. but just date is correct, time was wrong…! thanks!

    #32504

    @deciosouza,

    It seems to be working fine. The difference in time component could be because of time-zone difference. Setting time-zone should work fine in your case. Please refer this stackoverflow thread for more information on the same.
    new Date().toLocaleString("en-US", {timeZone: "America/New_York"})

    If you are still facing issue, kindly create sample project reproducing the issue you are facing and share it with us over Google-Drive or Onedrive along with sample data so that we can run it locally at our end to understand the scenario better and help you out.


    Vishwas R
    Team CanvasJS

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.