0

Hi hope someone can help me with the folowing:

    if( $verscil_huwelijksdat_tot_zestien_jaar->format('%R%a') >= 0 )
    {
        echo"bla bla";
    }

dosn't work

it only works when >=1 or <=-1 and wy not >=0 ?

Edited by johnnyd1963

3
Contributors
13
Replies
21
Views
3 Years
Discussion Span
Last Post by johnnyd1963
0

I'm not sure, but I don't think that that function is returning an integer, which is what you are comparing it against.

I suggest you check out what exactly is being returned by the format() function, e.g.:

var_dump($verscil_huwelijksdat_tot_zestien_jaar->format('%R%a'));
0

i give you here the code with what i am working with

$huwelijk_date_zestien = new DateTime("$geboorte_datum");
$huwelijk_date_zestien->modify('+16 years');
$huwelijk_date_zestien = $huwelijk_date_zestien->format('Y-m-d');

$dat_huwa = new Datetime("$datum_huwelijk");
$dat_huwelijk_echtgenote = date_format($dat_huwa, 'Y-m-d');

$dat_huwelijk_jaar_echtgenote = date_format($dat_huwa, 'Y');

$geboorte_datum_echtgenote = new DateTime($_POST['geboortedatum']);
$geb_dat_echtgenote = date_format($geboorte_datum_echtgenote, 'Y-m-d');
$geb_jaar_echtgenote =  date_format($geboorte_datum_echtgenote, 'Y');



if($dat_huwelijk_echtgenote > $huwelijk_date_zestien )
{
   $date1=new DateTime("$dat_huwelijk_echtgenote");
   $date2=new DateTime("$huwelijk_date_zestien");
   $verscil_huwelijksdat_tot_zestien_jaar = $date2->diff($date1);

    $date3=new DateTime("$geb_dat_echtgenote");
    $date4=new DateTime("$dat_huwelijk_echtgenote");
    $verschil_tussen_geboortedat_en_huwelijksdat = $date3->diff($date4);

    $date5=new DateTime("$geb_dat_echtgenote");
    $date6=new DateTime("$huwelijk_date_tien_jaar");
    $aantal_dagen_tot_tien_jaar =  $date5->diff($date6);

     }

if($dat_huwelijk_echtgenote < $huwelijk_date_zestien )
     {
       $date1=new DateTime("$dat_huwelijk_echtgenote");
       $date2=new DateTime("$huwelijk_date_zestien");
       $verscil_huwelijksdat_tot_zestien_jaar = $date1->diff($date2);

       $date3=new DateTime("$geb_dat_echtgenote");
       $date4=new DateTime("$dat_huwelijk_echtgenote");
       $verschil_tussen_geboortedat_en_huwelijksdat = $date4->diff($date3);

 }

if(  $verscil_huwelijksdat_tot_zestien_jaar->format('%R%a') <= 1  )
    {

      echo "bla bla";
      die();
    }

if( $verscil_huwelijksdat_tot_zestien_jaar->format('%R%a') >= 0  )
    {
        echo "bla bla";
        die();
    }
0

O yes
var_dump($verscil_huwelijksdat_tot_zestien_jaar->format('%R%a')); gives nothing on screen when $verscil_huwelijksdat_tot_zestien_jaar->format('%R%a') == 0

0

You should place the var_dump($verscil_huwelijksdat_tot_zestien_jaar->format('%R%a')); line before the if statement if you want to make sure it is executed :). Does it return an integer, a boolean, or something else? And what exactly?

0

so i said before it wil return noting on the screen and i did place it before the line if so i see nothing

0

%R%a is not from strftime() it's from DateInterval::format

Edited by johnnyd1963

0

i try to give var_dump($date1 == $date2);
and it answers me: bool(true)

0

Well, according to the examples in the manual, DateDiff::format() does not always return an integer. That's why I said: you should check what it is returning, because you're comparing it against an integer, and you cannot really compare a string value against an integer. If you know what I mean :). Maybe you can find another way to find out if this is what is happening, if var_dump() isn't returning anything (which I find weird, 'cause for as far as I know it always returns something and prints it on the screen).

0

wel i try to find something else.
about the var dump only return if the date_dif >=1 or <=1 but nothing when date_diff == 0 or >=0 or <=0.

when i
var_dump($verscil_huwelijksdat_tot_zestien_jaar->format('%R%a'));
when date_diff >=1 if gives string(2) "+1" d

Edited by johnnyd1963

0

Yes, so that basically means that the returned value is NOT an integer, right? :) So that means that you are comparing a non-integer against an integer, which is why your if() statement isn't working as you want it to. I guess you'll first need to convert the returned value ("+1 day") to an integer, and then throw it into your if() statement.

0

oke i give it a try tomorrow, I have to make a break now i com back tomorrow fot it. Thanks for the help until now.

0

i got the answer i saw a little mistype i forgot the = in

if($dat_huwelijk_echtgenote < $huwelijk_date_zestien ) in line 32 from the code i give before

it must be

if($dat_huwelijk_echtgenote <= $huwelijk_date_zestien )

and now it is working

Thanks for the help

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.