V
V
ValeraValera2017-07-20 16:06:33
PHP
ValeraValera, 2017-07-20 16:06:33

How to get only a list of dates by day if the records in the database contain a date field in the format 2017-07-20 09:00:47?

The wp_konkurs database contains records; they have a user_time field with a date and time in the format 2017-07-20 09:00:47
for one date there can be N records.
It is necessary to form a select in which only dates for the last 2 weeks will be displayed, for
example
, 2017-07 -01
2017-07-02
2017-07-N
now only the dates and times of the last 14 records are displayed, help me write a SQL query

<select class="form-control" id="sel1">
    <?php
    $userLists = $wpdb->get_results( 'SELECT  user_time FROM wp_konkurs  ORDER BY user_time DESC LIMIT 14 ');
      foreach($userLists as $count):
        echo "<option> $count->user_time </option>";
      endforeach;  ?>
</select>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2017-07-20
@cluberr

SELECT DISTINCT DATE_FORMAT(user_time, '%Y-%m-%d') date
FROM wp_konkurs
ORDER BY date DESC
LIMIT 14

https://www.w3schools.com/sql/func_mysql_date_form...

S
Sergey Sokolov, 2017-07-20
@sergiks

The MySQL DATE() function makes any date-time just a date.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question