0

I have date from monthpicker in this format: 2014 April , and i want to change it to 2014-04-01 before inserting it to mysql. I'm trying to use strtotime:

$b = date("Y-m-d", strtotime($_POST['month']));
echo $b;

Result is: 1970-01-01. I dont get it.

1

5 Answers 5

1

Use DateTime

$date = new DateTime("2014 April");
echo $date->format("Y-m-d");
Sign up to request clarification or add additional context in comments.

Comments

1
$date = DateTime::createFromFormat('Y F', '2014 April');
echo $date->format('Y-m-01');

Comments

0

Chances are month is being parsed incorrectly.

Try echoing strtotime($_POST['month']) - you will probably see a result of 0.

Try using DateTime function too,

$date = new DateTime("2014 April");
echo $date->format("Y-m-d");

Comments

0

Use strptime("date","format") - you can use same format as in date()

Comments

0

you can Use strtotime() and date()for PHP change date format:

$originalDate = "2014-04-06";
$yourDate = date("d-m-Y", strtotime($originalDate));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.