Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8935339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:58:01+00:00 2026-06-15T09:58:01+00:00

I have php code that returns this from a database, [ { Time: 2012-11-27

  • 0

I have php code that returns this from a database,

[
{
    "Time": "2012-11-27 16:10:35",
    "NumPlayers": "1"
},
{
    "Time": "2012-11-27 16:24:55",
    "NumPlayers": "1"
},
{
    "Time": "2012-11-27 16:25:37",
    "NumPlayers": "2"
},
{
    "Time": "2012-11-27 16:29:33",
    "NumPlayers": "2"

The times are MySQL timestamps. I need to get it into this format to use with Highcharts javascript charting.

data: [
[Date.UTC(1970,  9,  9), 0   ],
[Date.UTC(1970,  9, 14), 0.15],
[Date.UTC(1970, 10, 28), 0.35],
[Date.UTC(1970, 11, 12), 0.46],

I’m having trouble figuring out how to loop through the MySQL results and convert the timestamps to javascript Date.UTC objects. I need to place the NumPlayers value after the Date.UTC objects, and output it in the format below. I’m a PHP and javascript noob :\

It should look something like this:

data: [
[Date.UTC(2012, 11, 27, 16, 10, 35), 1],
[Date.UTC(2012, 11, 27, 16, 24, 55), 1],
[Date.UTC(2012, 11, 27, 16, 25, 37), 2],
[Date.UTC(2012, 11, 27, 16, 29, 33), 2],
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:58:02+00:00Added an answer on June 15, 2026 at 9:58 am

    You should realize that Date.UTC(2012, 11, 27, 16, 10, 35) simply returns the number of milliseconds since the epoch (1356624635000). Therefore, you can just convert your object into UNIX timestamps (times a 1000 since JS works with millisecond timestamps, but PHP works with seconds).

    Sample Code

    $data = '[{"Time": "2012-11-27 16:10:35", "NumPlayers": "1"}, {"Time": "2012-11-27 16:24:55", "NumPlayers": "1"}]';
    
    // Make sure date is parsed as UTC
    date_default_timezone_set("UTC");
    
    // Convert items into the desired format
    $mapper = function($item) {
        return array(strtotime($item->Time)*1000, $item->NumPlayers);
    }
    
    echo json_encode(array_map($mapper, json_decode($data)));
    

    Output

    [[1354032635000,"1"],[1354033495000,"1"]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following php code that gets a serialized array from a mysql
I have a php page that pulls data from a mysql database based on
I have this page that lists info from my mysql database. It requires an
I have this php code. As you can see i query a mysql database
I have a line of php code that looks like this: echo <script>$('#edit_errors').html('<h3><em>Please Correct
I have a need to create a library of Object Oriented PHP code that
I have a script that polls a MySQL database (Nagios, specifically) for the date/time
At this present point in time I have some code that does the following:
I have a php script that loads data from a database. The table I
I have experienced about two times that mysql database crashes and it can not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.