0

I request a date from datepicker by this line:

var checkIn=jQuery(".booking-date-fields).datepicker('getDate');

The output is:

Wed Dec 02 2015 00:00:00 GMT+0000 (Morocco Standard Time)

How can I format this using php or javascript to a YYYY-MM-DD format:

2015-12-02

Help help please !!!

2

1 Answer 1

1

In PHP you convert the string to UNIX time with strtotime and convert it as you wish with the date function:

//$_GET['checkIn']  = 'Wed Dec 02 2015 00:00:00 GMT+0000';
$getDate = $_GET['checkIn'];
$date = strtotime( substr( $getDate, 0, strpos( $getDate, '(' ) ) );
echo date( 'Y-m-d', $date );
// Output "2015-12-02"

Edit An ugly but working fix...

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

2 Comments

my url is : localhost:8081/villaGioconda/… i have code : $getDate=$_GET['checkIn']; $date = strtotime($getDate); echo date( 'Y-m-d', $date ); but i get in return 1970-01-01 !!! i must have output "2015-12-02"
I had to remove the parenthesis from the string. Now it should work!

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.