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 easier to use?

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);

Questions by bicu   answers by bicu

Showing Answers 1 - 2 of 2 Answers

Jitendra

  • Jul 3rd, 2006
 

Hi

  Just write down code below and do some change to have '@' char.

echo date('l dS of F Y h:i:s A');

  Was this answer useful?  Yes

deepika

  • Aug 9th, 2006
 

one can add any spl chars to date() function using "" with the required char.Try this for the give ques

echo date('l ,F d,  Y  @ h:i  a');

it wud return (day,month date, year @ hrs:minutesam)

njy......:)

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions