0

I'm trying to format a date from a post variable. When you type in: 05-05-2016 it will display as May 5, 2016. But when you type 05-12-2016, it will display as December 5, 2016. The format is below:

echo date("F d, Y", strtotime($wedding_date));

The format I would like is: Month Day, Year

1

2 Answers 2

1
echo date_format(date_create_from_format('m-d-Y', $wedding_date), 'F d, Y');

and adjust 'm-d-Y' to your needs (or input).

Sign up to request clarification or add additional context in comments.

Comments

1

Obviously there is an ambiguity in the input. So strtotime does not know what input format you delivered. You may consider using DateTime instead.

$out = DateTime::createFromFormat('d-m-Y', $weddingDay);
echo $out->format('F d, Y');

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.