Web Analytics Made Easy -
StatCounter How to insert any character in String - CodingForum

Announcement

Collapse
No announcement yet.

How to insert any character in String

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to insert any character in String

    Hello,

    I have a probelm in PHP. so plz help me.

    In DB, i have an field called 'request_date'. Its type is 'varchar'
    it gives result in that format:

    27092006_1
    27092006_2
    28092006_1
    28092006_2
    28092006_3

    here the values that comes before the underscore is the 'DATE' when that this record is inserted in DB.My requiement is that to show the current date,so for this i use explode function like


    PHP Code:
    $trip_post_date explode("_",$rst_trip['request_date']); 
    after that i got date in that format:

    27092006
    27092006
    28092006
    28092006
    28092006

    Now to display proper date, i want to add dashes in date like
    27-09-2006
    27092006
    28-09-2006
    28-09-2006
    28-09-2006

    HOW CAN I ADD THESE DASHES. plz help me in this regard.

    THanks
    Eshban

  • #2
    I'm thinking there's some MySQL method to give you the formatted date
    as you need it. But not sure how that works ...

    Here's another method:

    <?php
    $date="09272006";
    $newdate = substr($date,0,2)."-".substr($date,2,2)."-".substr($date,4,4);
    echo $newdate;
    ?>

    Comment


    • #3
      You could use strtotime() to convert the string into a timestamp then use date() to convert that into a date formatted as you want. But why not just use the DATE, TIME, DATETIME or TIMESTAMP datatypes for the column that stores that data?

      Comment

      Working...
      X