Page 1 of 1
changing the format of date
Posted: Sat Oct 18, 2008 6:00 am
by susrisha
Hello all.. I have written a query that returns dateTime field of mysql in the following format:
YYYY-MM-DD HH:MM:SS (Eg. 2008-10-31 16:40:00)...
I want to display this as (2008-10-31 4:40:00 PM)...
Can anyone tell me how to do this??
Thanks in advance
Re: changing the format of date
Posted: Sat Oct 18, 2008 6:27 am
by aceconcepts
Re: changing the format of date
Posted: Sat Oct 18, 2008 7:00 am
by susrisha
I think i didnt make myself clear..
The sql query returns me a string with the format as 2008-10-31 16:40:00 which happens to be taken as string in the query..
Code: Select all
$sql_time = "2008-10-31 16:40:00";
$my_reqd_format = "2008-10-31 4:40 PM";
is there any way i can convert from $sql_time to $my_reqd_format??
Think i am clearer this time..
Re: changing the format of date
Posted: Sat Oct 18, 2008 7:05 am
by aceconcepts
Ok, so what you need to do is the following:
Code: Select all
$my_reqd_format=date("Y-m-d G:iA", strtotime($sql_time));
Re: changing the format of date
Posted: Sat Oct 18, 2008 7:17 am
by susrisha
yaa now i got it.. thanx a tonn.. and its 'h' for the 12 hour format.. thanks alot anyway