samoht Posted July 10, 2007 Share Posted July 10, 2007 Hello again, I know this must be easy but I couldn't find an answer on google. I have a date returned from my db that is formated like 2007-07-10 I would like to hyper link that to the proper calendar page but I need the format to be 20070710 e.g. w/o the dashes How can I do this easily?? Thanks Link to comment https://forums.phpfreaks.com/topic/59286-strip-dashes-in-text/ Share on other sites More sharing options...
trq Posted July 10, 2007 Share Posted July 10, 2007 <?php $d = '2007-07-10'; $d = str_replace('-','',$d); ?> Link to comment https://forums.phpfreaks.com/topic/59286-strip-dashes-in-text/#findComment-294462 Share on other sites More sharing options...
per1os Posted July 10, 2007 Share Posted July 10, 2007 www.php.net/strtotime www.php.net/date www.php.net/str_replace or www.php.net/explode <?php $date = '2007-07-10'; $date_array = explode($date); $new_date = implode('',$date_array); echo $new_date ?> there the explode/implode example. Link to comment https://forums.phpfreaks.com/topic/59286-strip-dashes-in-text/#findComment-294463 Share on other sites More sharing options...
Wildbug Posted July 10, 2007 Share Posted July 10, 2007 Why not select it from the database in the format you want it in the program? mysql> SELECT date_or_datetime_col, DATE_FORMAT(date_or_datetime_col,'%Y%m%d') FROM tbl; +---------------------+--------------------------------------------+ | date_or_datetime_col| DATE_FORMAT(date_or_datetime_col,'%Y%m%d') | +---------------------+--------------------------------------------+ | 2007-04-30 20:52:25 | 20070430 | | 2007-04-27 12:00:00 | 20070427 | | 2007-01-01 12:00:00 | 20070101 | | 2006-05-01 00:00:00 | 20060501 | | 2007-01-02 13:00:13 | 20070102 | | 2007-03-31 09:00:00 | 20070331 | | 2007-03-30 01:00:00 | 20070330 | | 2007-05-01 00:00:00 | 20070501 | +---------------------+--------------------------------------------+ 8 rows in set (0.00 sec) Link to comment https://forums.phpfreaks.com/topic/59286-strip-dashes-in-text/#findComment-294481 Share on other sites More sharing options...
samoht Posted July 10, 2007 Author Share Posted July 10, 2007 Thanks Guys! I knew it was easy All of the suggestions work - but the simple string replace seems best for now. glad to know the other methods though! Thanks again Link to comment https://forums.phpfreaks.com/topic/59286-strip-dashes-in-text/#findComment-294568 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.