ereg on date and time

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
earny
Forum Newbie
Posts: 5
Joined: Tue Jul 21, 2009 10:22 am

ereg on date and time

Post by earny »

Hi

I have a date and time in one column as for example 2008-04-16 10:41:20.

I would like to do a ereg_replace so that the date and time will be converted only to date as 2008/04/16

I want to add the code to this
echo '<p> <a href=" '/' . $row['post_date'] . '/' . $row['post_name'] . '/ ">' . $row['post_title'] . '</a> <br>'. strip_tags(substr($row['post_content'],0,300)) . '';

so that $row['post_date'] changes to the new date structure and the URL will now read

http://www.bambooclat.com/2008/04/16/post_name/

thanks a bunch
Neal
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: ereg on date and time

Post by andyhoneycutt »

you could just use a combination of date() and strtotime():

Code: Select all

$post_date = date("Y/m/d",strtotime($row['post_date']));
-Andy
earny
Forum Newbie
Posts: 5
Joined: Tue Jul 21, 2009 10:22 am

Re: ereg on date and time

Post by earny »

thank you. I had to add one more thing to it to make it work the way i wanted it to. Here is what it now looks like

. $row['post_date'] = date("Y/m/d",strtotime($row['post_date']))
coalgames
Forum Newbie
Posts: 8
Joined: Sun Apr 26, 2009 12:22 am

Re: ereg on date and time

Post by coalgames »

By the way, you might want to learn pcre (preg_functions) because ereg is depreciated in 5.3.0 and will be removed in 6.0.0
earny
Forum Newbie
Posts: 5
Joined: Tue Jul 21, 2009 10:22 am

Re: ereg on date and time

Post by earny »

thanks a million. i will follow up on this
Post Reply