Member Avatar for OtepTheThird

Hi Php'ers,
I'm new to Php.

I have some issues INSERTING date to MySQL by PHP.
here's my code snippet:

//date format $date1 = mysqli_real_escape_string($_POST['j_avail']); $d1 = date('Y-m-d',($date1)); $date2 = mysqli_real_escape_string($_POST['j_expir']); $d2 = date('Y-m-d',($date2)); 

the query:

$sql = "INSERT INTO table (....,j_avail,j_expir) VALUES (....,'$d1','$d2')"; 

the HTML:

<td id="ititle">Availability :</td> <td><input type="date" name="avail" id="datep"></td> </tr> <tr> <td id="ititle">Expiration :</td> <td><input type="date" name="exp" id="datep"></td> </tr> 

When i execute my the code and check my db i get this 1970-01-01.
i also have tried strtotime it also gives me this result.

Dont know whats the issue here. hmmmm

Thanks.

OTEP

if you look at the manual:

http://php.net/manual/en/function.date.php

You see that the second parameter is a timestamp. You are passing a string (from the POST array), so I am wondering what you entered into it.

Do:

print_r($_POST['date1']); print_r($_POST['date2']); 

and show the output.

Member Avatar for Hilal2009

I know it, change to this one

$d1 = date('Y-m-d',(strtotime($date1))); $d2 = date('Y-m-d',(strtotime($date2))); 

I hope it will work fine, is 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.