tags:

views:

45

answers:

3

How can we convert Wed Jun 09 2010 which is returns from a javascript function and get in a php script.I need to convert this date format to 2010-06-09.Thanks

+1  A: 
<?php
$jsDateTS = strtotime($jsDate);
if ($jsDateTS !== false) 
 date('Y-m-d', $jsDateTS );
else
 // .. date format invalid
MANCHUCK
Thank you for your information
Ajith
A: 

Either you can send the javascript date to php via query string:

var mydate = encodeURIComponent('Wed Jun 09 2010');
document.location.href = 'page.php?date=' + mydate;

PHP

echo date('Y-m-d', strtotime(urldecode($_GET['date'])));

Or though a hidden field:

echo date('Y-m-d', strtotime(urldecode($_POST['date'])));
Sarfraz
@Sarfraz thank you for your response
Ajith
@Ajith: You are welcome
Sarfraz
A: 

Or with DateTime:

$date = new DateTime('Wed Jun 09 2010');
echo $date->format('Y-m-d');

The date format you can input to strtotime(), DateTime and date_create() are explained in the PHP manual. If you need more control over the input format and have PHP5.3, you can use:

$date = DateTime::createFromFormat('D M m Y', 'Wed Jun 09 2010');
echo $date->format('Y-m-d');
Gordon
@Gordon thank you for spending your valuable time for my problem
Ajith