Skip to content
Advertisement

How To Use Latest Date As A Condition In Query

I have a few table, and one of it is “peminjaman” which have “date” atribute type in it, which is “tarikhpemulangan” example=”2019-07-23″ . I want to select from “peminjaman” where the atribute “tarikhpemulangan” must already pass from today date. Please help me.

<?php

echo '<h4><script>
var dateObj = new Date();
var bulan = dateObj.getUTCMonth() + 1;//bulan 1-12
var hari = dateObj.getUTCDate();
var tahun = dateObj.getUTCFullYear();
newdate= hari + "-" + bulan + "-" + tahun;
document.write(newdate);
</script></h4>';

include 'capaian.php';

$query1 = "SELECT * FROM peminjaman INNER JOIN lulus ON 
peminjaman.nokppeminjam=lulus.nokppeminjam INNER JOIN peminjam ON 
peminjaman.nokppeminjam=peminjam.nokppeminjam WHERE tarikhpemulangan <= 
'newdate'";
$capai1 = mysqli_query($capaiDB, $query1);

?>

Advertisement

Answer

You just need to add NOW function on the query and we don’t need JavaScript code.

 include 'capaian.php';
 $query1 = "SELECT * FROM peminjaman INNER JOIN lulus ON 
 peminjaman.nokppeminjam=lulus.nokppeminjam INNER JOIN peminjam ON 
 peminjaman.nokppeminjam=peminjam.nokppeminjam WHERE tarikhpemulangan <= 
 NOW()";
 $capai1 = mysqli_query($capaiDB, $query1);
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement