Kvvaradha
Kvvaradha

Reputation: 842

Date format is not working with dd(Int)-Month(String)-yyyy(Int)

I have a form with some datepicker to select date fields. Here I have to save the date on database. the date format which I am using on jquery datepicker is " 12-Feb-2016". I want it to store it by reading the textbox value.

$posted['ad_close_date']. $ad_close_date = date('Y-m-d', strtotime(str_replace('-', '/', $_POST['ad_close_date'])));

enter image description here

but the above code gives me the result like this. 1970-01-01 , I don't know whats wrong in my code. How can I store it on database.

Upvotes: 0

Views: 91

Answers (1)

Deepak
Deepak

Reputation: 523

Try using:

date('Y-m-d', strtotime($_POST['ad_close_date']));

If you are passing 12-Feb-2016, else if you are passing an unix timestamp:

date('Y-m-d', $_POST['ad_close_date']);` 

Upvotes: 1

Related Questions