Jump to content

strip dashes in text


samoht

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.