changing the format of date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

changing the format of date

Post 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
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: changing the format of date

Post by aceconcepts »

Code: Select all

$yourDate=date("Y-m-d G:i:sA");
Take a look at: http://uk.php.net/date
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: changing the format of date

Post 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..
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: changing the format of date

Post 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));
 
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: changing the format of date

Post by susrisha »

yaa now i got it.. thanx a tonn.. and its 'h' for the 12 hour format.. thanks alot anyway
Post Reply