-1

I want to execute a if statement where I want if given {date} is less or equal than today then {due_amount}= {paidbystudent} else {due_amount}= '0'

Here is my code:

if ({date} <= Today()) {
    {due_amount}={paidbystudent};
}  else {
    {due_amount}='0';
}

But its not working. Please help me how to do this.

I have also tried this code but its not working properly this is checking only date and ignoring month and year

$todays_date=date("d/m/Y", strtotime("today"));
$date=date("d/m/Y", strtotime({date}));

if ($date <= $todays_date) {
    {due_amount}={paidbystudent};
}  else {
    {due_amount}='0';
}
Thibault
  • 1,566
  • 15
  • 22
user3210029
  • 45
  • 1
  • 1
  • 12

1 Answers1

4

How about this:

$date = '2014-05-22'; // fetch from db, user input etc   

if (strtotime($date) <= time()) {
    echo 'paid by student';
} else {
    echo 0;
}

DEMO

EDIT: As pointed out by deceze, a better way to approach this would be to compare the UNIX timestamp values instead of a date format.

asprin
  • 9,579
  • 12
  • 66
  • 119