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

  • Home
  • SEARCH
  • 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 8864813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:20:47+00:00 2026-06-14T16:20:47+00:00

$SQLString = SELECT count(score) as counts, score, month, date FROM persons GROUP BY day,

  • 0
$SQLString = "SELECT    
                count(score) as counts,
                score, month,
                date FROM persons  
                GROUP BY day, month, year 
            ORDER BY date asc";     

    $result = mysql_query($SQLString);   
    $num = mysql_num_rows($result);   


$data[0] = array('day','counts');       
    for ($i=1; $i<($num+1); $i++)
    {
        $data[$i] = array(substr(mysql_result($result, $i-1, "date"), 0, 10),
            (int) mysql_result($result, $i-1, "counts"));
    }   
    echo json_encode($data);

This outputs something like this:

[["day","counts"],["2012-01-20",1],["2012-02-06",1],["2012-11-16",2],["2013-04-13",1]] 

My problem is that I need that date values (eg. “2012-01-20”) in date type instead of string.

I really need your help…

  • 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-14T16:20:49+00:00Added an answer on June 14, 2026 at 4:20 pm

    MySQL date values ARE strings. If you stored them as plaintext, they’d be seen as integer subtractions, e.g.

     2012-01-02 -> 2012 minus 1 minus 2 -> 2009
    

    Javascript has no native “date” strings. There’s only the Date object, which can’t be represented in a JSON string. If you want integers, you’ll have to store them as unix timestamps, e.g.

    2012-01-20 00:00:00 -> 1327039200
    

    However, note that Javascript uses milliseconds for its timestamp values, so you’d need

    1327039200000
    

    as the value to pass through.

    Note that your code is highly inefficient. mysql_result is painfully slow, and ugly to work with. You could simply things greatly with

    $sql = "SELECT COUNT(score) AS counts, unix_timestamp(yourdatefield) AS timestamp ...";
    
    $data = array();
    while($row = mysql_fetch_assoc($result)) {
       $timestamp = $row['timestamp'];
       $data[] = array($row['counts'], $row['timestamp'] * 1000);
    }
    echo json_encode($data);
    

    then you can convert those timestamps to have JS date objects with

    var d = new Date(1327039200000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$SQLString = SELECT count(score) as counts, DATE(date), SUM(CASE WHEN gender = 1 then 1
select substring(datapath,1,5), COUNT(substring(datapath,1,5)) from batchinfo where datapath like '%thc%' group by datapath having COUNT(substring(datapath,1,5))>1
So I have the following SELECT statements: SELECT COUNT(A.Award) AS US, SUBSTRING(CAST(M.Year as char(4)),
I'm trying to display the result of an MYSQL select count as a hyperlink
DBMS is PostgreSQL. In controller: @data = current_user.myitems.all(:select => 'record_date, count(record_date) as value', :group
I'm trying to select distinct substring values of a field and count the number
protected static Boolean Authentication(string username, string password) { string sqlstring; sqlstring = Select Username,
Question: Given a SQL string like CREATE VIEW TestView AS SELECT value1, value2 FROM
How can I delete the records returned by the following query? Select HL.User from
SELECT * FROM [productDetail] WHERE Price BETWEEN 0 AND 2000 OR Price BETWEEN 2000

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.