Page 1 of 1

ereg on date and time

Posted: Tue Jul 21, 2009 10:41 am
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

Re: ereg on date and time

Posted: Tue Jul 21, 2009 11:03 am
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

Re: ereg on date and time

Posted: Tue Jul 21, 2009 12:38 pm
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']))

Re: ereg on date and time

Posted: Tue Jul 21, 2009 3:00 pm
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

Re: ereg on date and time

Posted: Tue Jul 21, 2009 5:28 pm
by earny
thanks a million. i will follow up on this