Hello.

So, I have 2 questions.

First is:

I am trying to calculate the expiration date which will be calculated as adding the current date + the option that has been select i.e. 30, 60 or 90 days.

    $EXday = date('d', mktime(0,0,0,0, date(d) + $_POST[exdays], 0));
    $EXmonth = date('m', mktime(0,0,0, date(m), date(d) + $_POST[exdays], 0));
    $EXyear = date('Y', mktime(0,0,0,date(m) ,date(d) + $_POST[exdays], date(Y)));





<tr>
    <td>

    This offer expire after: 
    </td>

    <td>
    <select name="exdays">
    <option value="30"> 30 </option>
    <option value="60"> 60 </option>
    <option value="90"> 90 </option>
    </select>
     days. 
    </td>
    </tr>

2nd question is:

When I perform my Insert Statement, instead of getting a value in one of the field I get "Array", but the rest of statement seems to be ok.

I am using a radio button similar to the one I just posted about the expiration date.

Firstly, u need to have the posted data in single quotes like so;

$EXday = date('d', mktime(0,0,0,0, date('d') + $_POST['exdays'], 0));

Do the same to the other records

Regarding the date try:

date('d-m-Y', mktime(0, 0, 0, date("m"), date("d") + $_POST['exdays'], date("Y")));

Concerning the second question, you can use json_encode() to convert the array to a string and so, you can save it as varchar or text type, otherwise you need a blob type.

Edit
Sorry Webville, I just saw your reply, bye!

No problemo cereal ...

Member Avatar for diafol

I'd suggest DateTime object as thast deals easily with overflows too:

$x = (int) $_POST['exdays'];
if(in_array($x, array(30,60,90)){
    $date = new DateTime();
    $date->add(new DateInterval('P'.$x.'D'));
    echo "NEW DATE: " . $date->format('Y-m-d') . "\n";
};

Thank you guys, it works like a charm.

Just using Webville's suggestion fixed both of my problems, hah.

Diafol, thank you for the suggestion. I'll have a look at it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.