How to SELECT All Data using Date Today in PHP
Submitted by alpha_luna on Monday, October 10, 2016 - 10:32.
In this tutorial, we are going to learn how to SELECT All Data using Date Today in PHP. This source code is a simple guide to the beginners who really want to know how to select all MySQL Data from today date. We are going to use the PDO object in PHP to select data using the date.
We have example MySQL table and it's called "tbl_topic". Take a look in the picture below.
In the end column of the "tbl_topic" table, as you can see in the image above, we have DATETIME column and it's called "date_submit". It all means that if the column have any Date inserted in the "tbl_topic" table, this would be the example value.
Example
- 2016-09-22 07:28:16
- 2016-09-22 18:11:26
- 2016-09-23 10:26:12
- 2016-09-23 16:08:22
- <?php
- $conn = new PDO("mysql:host=localhost;dbname=select_all_using_dateToday", 'root', '');
- $result = $conn->prepare("SELECT * FROM tbl_topic where DATE(date_submit)=CURDATE() ORDER BY tbl_topic_id DESC");
- $result->execute();
- ?>
As you can see in the source code above:
- We already assigned the SELECT Statement to the Date today by providing the date function.
- We constructed the SELECT Statement Query. Using this simple query, we use the DATE() Function, which we can get the date segment in DATE or DATETIME format. It includes the Hour, Minutes, and Seconds part in the date_submit column in the table.
- Preparing the SELECT Statement.
- Execute the SELECT Statement with DATE() Function.
- Fetched Data Results using fetchall() Function.
Add new comment
- 101 views