How to Get Yesterday and Tomorrow using MySQL SQL Query

Select your language

How to Get Yesterday and Tomorrow using MySQL SQL Query

Problem: You need to fetch previous days record from a table which has date column.

Solution: You will use Joomla Form API.

<?php

$servername = "localhost"; $username = "youruser"; $password = "yourpass"; $dbname = "DBname"; // Now make connection $conn = new mysqli($servername, $username, $password, $dbname); // Then test connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql ="SELECT * FROM <tablename> WHERE date(on_date) = curdate() - INTERVAL 1 DAY"; $result = $conn->query($sql); if ($result->num_rows > 0) { // Now output data of each row while($row = $result->fetch_assoc()) { echo "<div>".$row["id"]." : ".$row["firstname"]." ".$row["lastname"]."</div>"; } } else { echo "0 results"; } $conn->close();


?>