skip to Main Content

i have an Array with this string value.

[VALIDUNTIL] => 28.08.23

Now i need to compare it with the todays date and check if the VALIDUNTIL date is in the same month and year as the today´s date
i looked for a while now but i cant find any solution.

while ($row = oci_fetch_assoc($dbResult)) 
{
    $data[] = $row;
}


foreach($data as $ar) {
    if ($ar['VALIDUNTIL'] && $ar['VALIDUNTIL'] != null) {   
        if(strtotime($ar['VALIDUNTIL']) >= strtotime($date)) {
           
        }   
    }

When i try to do it with timestamps it cant read the VALIDUNTIL date and gives me the 1970 timestamp
strtotime seems not to work too.
tnx 4 help.

2

Answers


  1. Here are the PHP string conversions for time ref. https://www.w3schools.com/php/php_ref_date.asp

      echo(strtotime("now") . "<br>");
      echo(strtotime("3 October 2005") . "<br>");
      echo(strtotime("+5 hours") . "<br>");
      echo(strtotime("+1 week") . "<br>");
      echo(strtotime("+1 week 3 days 7 hours 5 seconds") . "<br>");
      echo(strtotime("next Monday") . "");
      echo(strtotime("last Sunday"));
    

    You’d need to have both dates in the same format. The above is from : https://www.w3schools.com/php/func_date_strtotime.asp#:~:text=The%20strtotime()%20function%20parses,are%20mapped%20to%201970%2D2000.

    if you echo (strtotime($ar[‘VALIDUNTIL’]) and strtotime($date)) back to the screen then you can visually compare and check to see the format which you are using is the same for both dates and adjust accordingly.

    Login or Signup to reply.
  2. while ($row = oci_fetch_assoc($dbResult)) 
    {
        if(!empty($row['VALIDUNTIL']) && !is_null($row['VALIDUNTIL'])){
           $valid_date = date('d-m-Y', strtotime($row['VALIDUNTIL']));
           $current_date = date('d-m-Y');
           if($valid_date >= $current_date ) {
              echo "True";
           }   
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search