A Brief Discription

My photo
Hello friends, first of all i would like to tell you about myself that your friend is a very small part of this world same like you. I m a 24 years old man and don't feel till now that i am adult.Professionally i m a web developer in pink city in India.

Tuesday, August 18, 2009

If you have to work with dates in the following format: "Tuesday, February 14, 2006 @ 10:39 am", how can you convert them to another format, that is e

The strtotime function can convert a string to a timestamp. A timestamp can be converted to date format. So it is best to store the dates as timestamp in the database, and just output them in the format you like.

So let's say we have
$date = "Tuesday, February 14, 2006 @ 10:39 am";
In order to convert that to a timestamp, we need to get rid of the "@" sign, and we can use the remaining string as a parameter for the strtotime function.

So we have
$date = str_replace("@ ","",$date);
$date = strtotime($date);

now $date is a timestamp
and we can say:

echo date("d M Y",$date);

No comments:

Post a Comment