SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict AbelaJohnB's Avatar
    Join Date
    Oct 2001
    Location
    Eureka, CA. USA
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Convert 19730405 To: 04/05/1973

    Hello All.


    I have a varible containing a date, which I need to convert.




    Convert 19730405 To: 04/05/1973



    Anybody have suggestions?



    Thanks.
    John B. Abela
    www.JohnAbela.Com

  2. #2
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can use the following function:
    PHP Code:
    <?
    function timestamp_convert($timestamp

    $year substr($timestamp04); 
    $month substr($timestamp42); 
    $day substr($timestamp62); 

    $new_date $month."/".$day."/".$year
    return 
    $new_date
    }
    ?>
    Last edited by Defender1; Dec 14, 2001 at 05:22.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  3. #3
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Assuming that this is a fixed length string (8 chars):

    PHP Code:
    <?php

    $dateStr 
    '19730405';

    $year substr($dateStr04);
    $month substr($dateStr42);
    $day substr($dateStr62);

    $formattedDateStr "$month/$day/$year";

    ?>
    I have assumed the American standard date format (M/d/Y)

  4. #4
    SitePoint Addict AbelaJohnB's Avatar
    Join Date
    Oct 2001
    Location
    Eureka, CA. USA
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank You Guys!


    You guys got the brain-juices flowing again


    talk about programmers-block... wow, the mind just froze on this one!


    Anyway, here is what I worked.

    It checks for pre 1000 year dates too.






    PHP Code:
    <?php
    function timestamp_convert($str_input

        
    $year substr($str_input04); 
        
    $month substr($str_input42); 
        
    $day substr($str_input62); 
        
    ////////////////////////////////////////
        // DETECT ZERO STARTING YEAR
        ////////////////////////////////////////
            
    $year1 substr($year01);
            if (
    $year1 == "0") {
                
    $year substr($str_input13);
            } else {
                
    $year substr($str_input04);
            }
        
    ////////////////////////////////////////
        //
        
    $new_date $month."/".$day."/".$year
      return 
    $new_date
    }

    print 
    timestamp_convert("09090414");
    ?>

    Again, thanks guys.
    Last edited by AbelaJohnB; Dec 14, 2001 at 05:45.
    John B. Abela
    www.JohnAbela.Com

  5. #5
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BTW, there is a known bug with the PHP tags that has crept into the forums, with the upgrades that Wayne has recently introduced.

    To get around it make sure you include the opening and closing <?php and ?> tags in your code when you post!


  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Uh.. Am I missing something here, or are you guys making this way more difficult than it needs to be.

    PHP Code:
    <?php
    $date 
    19730405;
    $date date("m/d/Y"strtotime($date));
    ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •