Link Worth

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?

Written on July 22, 2007 – 6:37 am | by Prakash Thapa |

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

[code]
$date = “Tuesday, February 14, 2006 @ 10:39 am”;
[/code]

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
[code]
$date = str_replace(”@ “,”",$date);
$date = strtotime($date);
[/code]

now $date is a timestamp
and we can say:

[code]
echo date(”d M Y”,$date);
[/code]

Related Posts

Put your related posts code here

Post a Comment

About Me

I am Prakash Thapa a Freelancer Web Programmer and this is my personal blog. Since from the beginiing of my journey in this Web World I have learned so many things by self-study. And have completed so many web-projects. Currently I am running my own web-house "ITWeb Developer" at Kathmandu, Nepal... More

Want to subscribe?

 Subscribe in a reader Or, subscribe via email:
Enter your email address:  

Our Sponsors


Translate This Blog

English flagItalian flagGerman flagSpanish flagFrench flagPortuguese flagJapanese flagKorean flagChinese flagArabic flagRussian flag
Find entries :