Jump to content

Barand

Moderators
  • Posts

    24,345
  • Joined

  • Last visited

  • Days Won

    795

Posts posted by Barand

  1. When I need to extract chart data covering a range of dates I find it easier to create a temporary table containing all the dates that I need to show on the chart. I use a DatePeriod object to create the range of dates EG

    mysql> select * from tempdate;
    +---------+
    | month   |
    +---------+
    | 2016-01 |
    | 2016-02 |
    | 2016-03 |
    | 2016-04 |
    | 2016-05 |
    | 2016-06 |
    | 2016-07 |
    | 2016-08 |
    | 2016-09 |
    | 2016-10 |
    | 2016-11 |
    | 2016-12 |
    +---------+
    

    So if I have a revenue table like yours ...

    mysql> select * from revenue;
    +---------+---------+
    | month   | revenue |
    +---------+---------+
    | 2016-05 |      20 |
    | 2016-08 |      10 |
    | 2016-11 |      50 |
    +---------+---------+
    

    ... I can fill in the gaps with

    SELECT t.month
      , IFNULL(r.revenue, 0) as revenue
    FROM tempdate t 
    LEFT JOIN revenue r USING (month);
    
    +---------+---------+
    | month   | revenue |
    +---------+---------+
    | 2016-01 |       0 |
    | 2016-02 |       0 |
    | 2016-03 |       0 |
    | 2016-04 |       0 |
    | 2016-05 |      20 |
    | 2016-06 |       0 |
    | 2016-07 |       0 |
    | 2016-08 |      10 |
    | 2016-09 |       0 |
    | 2016-10 |       0 |
    | 2016-11 |      50 |
    | 2016-12 |       0 |
    +---------+---------+
    
  2. So for it to work as it did with a separate time column, are the time elements the same in the two datetime columns?

     

    When comparing a date with a datetime column you need to use only the date portion of the datetime.

     

    So if my opening assumption is true

    SELECT id
    , schedule_start
    , schedule_end
    WHERE
        UTC_DATE() BETWEEN DATE(schedule_start) AND DATE(schedule_end)
            AND EXTRACT(HOUR_MINUTE FROM UTC_TIME()) = EXTRACT(HOUR_MINUTE FROM schedule_start)

     

  3. This is the part that is confusing me. How do i echo it out as DDMMYY

     

     

     

    You could try reading thara's post again and use the function he gave you.

     

    edit - alternatively you can do it in PHP

    $dtobj = new DateTime($row['date']);
    echo $dtobj->format('d/m/Y');               //--> 23/01/2017, for example
    
    • Like 1
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.