Why is this if shown?

0

I have this if, that supposedly if NO is Sunday and a certain date has to be shown, that works, but I need to edit the date like this, by variables, and when changing it by variables it is always shown, as if the condition be fulfilled, and it's not like this:

$vd="01";
$vm="08";
$suma="4";
$vdr= $vd+$suma;

        <div class="col-md-12 col-sm-12">
            <div class="row">
                  <?php
                  if($quediaes!="Sun"  && "08-08-2018" <= $fecha || $fecha <= "$vdr-$vm-2018"){
                   include('domingo.php'); 
                 }
                   ?>
            </div>
        </div>
    
asked by MatiPHP 10.09.2018 в 01:12
source

1 answer

0

It seems that your problem is logic in the use of variables, since you try to add 2 string , when you only concatenate them, that is, as the values of the variables are in quotes, then you concatenate them $vd+$suma; .

As a result, you will throw "01"+"4" = "014" . So, if you want to do mathematical operations with the variables you must put them without double quotes "" :

Example:

$fecha = date('Y-m-d');
//sumas o restas dias, en este caso el estamos 8 dias teniendo en cuenta que hoy estamos a 9
$nuevafecha = strtotime ( '-8 day' , strtotime ( $fecha ) ) ;
//sumas o restas meses
// $nuevafecha = strtotime ( '+1 month' , strtotime ( $fecha ) ) ;
//sumas o restas años
// $nuevafecha = strtotime ( '+2 year' , strtotime ( $fecha ) ) ;
// deja la que necesites y aqui le das el nuevo valor
$nuevafecha = date ( 'Y-m-d' , $nuevafecha );



<div class="col-md-12 col-sm-12">
    <div class="row">
          <?php
//primero comparas que $quediaes sea diferente "Sun", luego en el otro parentesis que alguna de las dos fechas sean inferiores
          if($quediaes!="Sun"  && ("01-05-2018" >= $fecha || $fecha <= $nuevafecha)){
           include('domingo.php'); 
         }
           ?>
    </div>
</div>

Note: Seeing that what you need is to operate with the dates, here I modify the answer in which you can play with the dates, and the conditional for the range of dates would be like this, so that the variable $fecha is in that time range.

    
answered by 10.09.2018 в 01:43