2

I am using datePicker for date selection in the front end. I have shown date like this:

September,30 2012

But when I receive it in PHP and try to convert it into date format, it generates wrong date.

$var = date('Y-m-d', strtotime('September,30 2012'));

The above gives me 1970/01/01.

4 Answers 4

4

Just remove the , from the datepicker's output..And it'll be fine

$var = date('Y-m-d', strtotime('September 30 2012'));

gives you 2012-09-30

And to remove comma,use

$daf = 'September 30 2012';
echo str_replace(',','',$daf); // gives September 30 2012
Sign up to request clarification or add additional context in comments.

Comments

1

This may work

 $var = date('F d y', strtotime('September 30 2012'));

Comments

0

i think its the comma that is doing that... removing comma gives u correct answer.. try this

echo date('Y-m-d',strtotime('September 30 2012'));

Comments

0

just remove the comma and you get the solution

<?php
    $date = 'September,30 2012';
echo $var = date('Y-m-d', strtotime('September-30-2012')); //this gave me 1970/01/01

or just remove the dash it works in both scenario

Here is the working solution

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.