0

I am passing jQuery date in backend. date is Thu Jun 01 2017 00:00:00 GMT 0530 (India Standard Time).

I want to convert this date in 2017-06-19 this format but in php.

$date_str='Thu Jun 01 2017 00:00:00 GMT 0530 (India Standard Time)';
echo  date_format(date_create_from_format('Y-m-d', $date_str), 'd-m-Y');

I have tried this solution but it is not working for me.

2
  • How do you want the solution? from php level or jquery level? Commented Aug 10, 2017 at 5:06
  • I want solution in php level Commented Aug 10, 2017 at 5:07

2 Answers 2

1

You can use this code:

$timezoneDataStartPos = strpos($date_str," GMT");
$formattedString = substr($date_str, 0, $timezoneDataStartPos);
$formattedDate=DateTime::createFromFormat('D M d Y H:i:s', $formattedString, new DateTimeZone('Asia/Kolkata'));
echo $formattedDate->format('Y-m-d');

You need to remove " GMT 0530 (India Standard Time)" and make sure to preserve Timezone as Asia/Kolkata

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

2 Comments

if user using from other country then there is no GMT0530 then there is some other timezone
Edited the code, now it should work :) @chirag-satapara
0

Try this code:

Note : Remove 0530 (India Standard Time) from your date format and use date format shown below my code.

<?php
$date_str='Thu Jun 01 2017 00:00:00 GMT ';
echo date('Y-m-d',strtotime($date_str));
?>

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.