+ 2
Hi! Please, i want to retrieve from the table all the records saved during the month of Mars like in description. Please help!
TABLE: [Date | Amt | Paymt ] [2/1/18 2000 Crédit ] [2/1/18 2000 Express] [3/2/18 2000 Express] [3/2/18 1000 Express] [3/3/18 2000 Crédit ] [4/3/18 2000 Express] [4/4/18 2000 Express] Result after sql query from table : retrieve records saved on the month of mars. TABLE: [Date | Amt | Paymt ] [3/3/18 2000 Crédit ] [4/3/18 2000 Express]
6 Answers
+ 9
I believe you're looking for SQL solution to retrieve the records on March.
Perhaps you can specify the DBMS you're targetting as we might have different answers for T-SQL (Microsoft), PL-SQL (Oracle), MySQL, PostgreSQL, IBM DB2 and so on.
P/S: There's a difference between getting records on March only or March 2018. đ
+ 4
I assume you mean March and not mars!
You could simply run a query to select all dates between 1/3/2018 and 30/3/2018.
I would suggest using PDO for best practices as showen below. Also if your column name in your DB is called Date then i would change this as the word Date is used alot within PHP and MYSQL and will conflict.
First get or post your from date and to date, not sure how your carrying this across but lets say you use a GET from the URL.
$DateFrom = $_GET['datefrom'];
$DateTo = $_GET['dateto'];
$stmt2 = $pdo->prepare('SELECT * FROM table WHERE dateColumn BETWEEN :DateFrom AND :DateTo');
$statement->bindValue(':DateFrom', $DateFrom);
$statement->bindValue(':DateTo', $DateTo);
$statement->execute();
Hope this helps you.
+ 3
Hemath Kumar thank for your proposal. I have tried your query and it works. But i want it To be dynamic that is, it get the current month of the year and execute the query base on the month. example if march, it filter March else if April, it filter base on april.
+ 2
Zephyr Koo thank for your respond. Am using both Mysql and Microsoft Access DB system. And am working on window form application.
+ 1
for this, just use php's DATE function bro....!!
Have a look at PHP Dates in Google or here....!!
I think it may help you!!
0
Query:
SELECT * FROM table_name BETWEEN from AND to;
Replace the from date with 01-03-2018
and to date
31-03-2018
I think this may help you!!
If you are still struggling, just mention my name in the comment, I will provide complete solution!!