Hello

I want to convert the date formate from

Wed Jun 15 2011 00:00:00 GMT 0530 (India Standard Time)

to

06/06/2011

I have done something like this

$chkdt = "Wed Jun 15 2011 00:00:00 GMT 0530 (India Standard Time)";
	$month = substr($chkdt,4,3);
	if($month == 'Jan') $month = '01';
	else if($month == 'Feb') $month = '02';
	else if($month == 'Mar') $month = '03';
	else if($month == 'Apr') $month = '04';
	else if($month == 'May') $month = '05';
	else if($month == 'Jun') $month = '06';
	else if($month == 'Jul') $month = '07';
	else if($month == 'Aug') $month = '08';
	else if($month == 'Sep') $month = '09';
	else if($month == 'Oct') $month = '10';
	else if($month == 'Nov') $month = '11';
	else if($month == 'Dec') $month = '12';
	
	$date = substr($chkdt,7,3);
	$year = substr($chkdt,10,5);
	$finaldt = date("m/d/Y", mktime(0, 0, 0, $month, $date, $year));

its working fine and give me the result which i want. but i don't want to use this if condition for the each month. is there any other solution for convert the date in same formate which i want ?

Thanks in advance :)

Check this.

<?
	echo $strDate = substr('Wed Jun 15 2011 00:00:00 GMT 0530',4,11);
	echo '<br />'.date('m/d/Y', strtotime($strDate));
?>
commented: Thanks for your help. it solved my problem. +3
$chkdt = "Wed Jun 15 2011 00:00:00 GMT 0530 (India Standard Time)";
$chkdtarr=explode("GMT",$chkdt);
$newdt= strtotime($chkdtarr[0]);
echo $newdt;
echo "<br>".date("m/d/Y",$newdt);
Member Avatar for diafol
<?php

function getTime($date,$inctime=true,$tz1="Europe/London",$tz2="Asia/Kolkata"){
	date_default_timezone_set($tz1);
	$int = strtotime(substr($date,0,24));
	date_default_timezone_set($tz2);
	$tm = ($inctime) ? ' H:i:s' : '';
	return date("d/m/Y$tm",$int);
}

echo getTime("Wed Jun 15 2011 10:00:00",true);

?>

//OOPS, OK just saw the GMT +530 bit - so your time is already,local - no need to convert, as mentioned previously, just split the string and use strtotime.

you could fix your database design by a tableupdate now, and
store only a timestamp,
use 4bytes per record instead of 35,
require simpler code to select records,
simpler code to update the table,
simpler code to display
allow any user to have the date and time formatted to their preference, or their country code standard

correct the problem, intead of patch it, and make the whole thing much easier elseif() is fractionally faster than else if()

commented: your answer is not related to the question. -1

@ all
thanks for your help. Its working for me :)

@almostbob
I am not store this formate into db this date value I get it from event calender and I can't change that calender so I have to convert this date into my required formate.

$chkdt = "Wed Jun 15 2011 00:00:00 GMT 0530 (India Standard Time)";
$finaldt = date("m/d/Y", strtotime($chkdt));

and still repair your data

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.