Jump to content

[solved]date help thank you.


redarrow

Recommended Posts

Thank you.


Please can you help $months_payed_for 11 and 12 not working any advice please cheers.

all the other conditions with date work but 11 and 12 any idears cheers.

[code]
<?php

if($months_payed_for=="1"){

$d=date("d")+7;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);

$price="£5";

}elseif($months_payed_for=="2"){


$d=date("d")+14;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);

$price="£10";

}elseif($months_payed_for=="3"){


$d=date("d")+21;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);

$price="£15";

}elseif($months_payed_for=="4"){


$d=date("d")+28;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);

$price="£20";

}elseif($months_payed_for=="5"){


$d=date("d")+35;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);

$price="£25";

}elseif($months_payed_for=="6"){


$d=date("d")+42;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);


$price="£30";

}elseif($months_payed_for=="7"){


$d=date("d")+49;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);

$price="£35";

}elseif($months_payed_for=="8"){


$d=date("d")+56;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);

$price="£40";

}elseif($months_payed_for=="9"){


$d=date("d")+63;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);

$price="£45";

}elseif($months_payed_for=="10"){


$d=date("d")+70;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);

$price="£55";

}elseif($months_payed_for=="11"){


$d=date("d")+77;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);

$price="£60";

}elseif($months_payed_for=="12"){

$d=date("d")+94;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);

$price="£65";
}
?>[/code]
Link to comment
Share on other sites

This is solved the only way i could come up with was using the time() stamp thanks to the grate php.net cheers all.


solved



[code]

<?php

if($months_payed_for=="1"){

$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+7, date("Y", $now));

$price="£5";

}elseif($months_payed_for=="2"){


$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+14, date("Y", $now));

$price="£10";

}elseif($months_payed_for=="3"){

$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+21, date("Y", $now));
$price="£15";

}elseif($months_payed_for=="4"){


$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+28, date("Y", $now));

$price="£20";

}elseif($months_payed_for=="5"){


$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+35, date("Y", $now));

$price="£25";

}elseif($months_payed_for=="6"){


$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+42, date("Y", $now));

$price="£30";

}elseif($months_payed_for=="7"){

$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+49, date("Y", $now));

$price="£35";

}elseif($months_payed_for=="8"){

$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+56, date("Y", $now));

$price="£40";

}elseif($months_payed_for=="9"){

$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+63, date("Y", $now));

$price="£45";

}elseif($months_payed_for=="10"){

$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+70, date("Y", $now));

$price="£55";

}elseif($months_payed_for=="11"){


$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+77, date("Y", $now));

$price="£60";

}elseif($months_payed_for=="12"){

$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+94, date("Y", $now));

$price="£65";
}

[/code]
Link to comment
Share on other sites

Well, your definition of working must be different to mine

Take your "$months_paid_for = 1" case

[code]
$d = date('d')+7;
$exspire_date=date("$d-m-y");
echo $exspire_date;                  // ---> 32-08-06 !!!
[/code]

I suggest you RTFM re date() format strings

Also if they pay for x months, why is the expiry date calculated by adding  7 * x days. There are 7 days in a week, not a month ???

As Orio pointed out, the price is the number of months * 5, until 10 months and above when an extra fiver gets added.

This might be closer
[code]
<?php
echo '<pre>';
for ($months_payed_for=1; $months_payed_for<=12; $months_payed_for++)  {
    $expire_date = date ('d-m-Y', strtotime("+$months_payed_for months"));
    $price = "£".(5*$months_payed_for);
    printf ('%2d %12s %5s<br>', $months_payed_for, $expire_date, $price);
}
echo '<pre>';

?>[/code]
Link to comment
Share on other sites

[quote]
$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+77, date("Y", $now));

$price="£60";

}elseif($months_payed_for=="12"){

$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+94, date("Y", $now));

$price="£65";[/quote]

With your mathematical ability I really would recommend using PHP to calculate 12 * 7 and not hard-code the values. ;) (Or is the extra 10 days a deliberate bonus?)

If you just want to use the current time() values, date('m'), date('d') and date('Y') will suffice.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.