SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2002
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problems With Date Conversion

    I use the timestamp date('YmdHis') so that i can use that time and date to display, however, it never gives me the correct month. this is the basic setup of my timestamp, what i want to do is, take the month, and change it to something like Jan, Feb, Mar, Apr, etc.:
    PHP Code:
    <?php
    /*Random Timestamp. Reads:
    YYYYMMDDHHIISS, in this example, output should be:
    2002 Aug 02 18(which will be converted to 12) 53 21*/
    $timestamp2 20020902185321;
        
    $date substr($timestamp208);
        
    $time substr($timestamp286);
            
    $h substr($time02);
            
    $i substr($time22);
            
    $s substr($time42);
                
    $h $h-6;
        
    $time $h $i $s;
    /*Where it should convert to a readable month*/
        
    $date date('M'$timestamp2);
    echo 
    $date"<br>";
    echo 
    $time"<br>";
    can someone help me?
    InQuE

  2. #2
    SitePoint Enthusiast ericthehalfbee's Avatar
    Join Date
    Oct 2001
    Location
    Auckland, NZ
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wish I could.
    I thought I understood these things but clearly not, I await an answer with interest.

    Eric

  3. #3
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to convert the timestamp to a unixtime stamp with mktime().

    PHP Code:
    $timestamp 20020902185321;
    $year   substr($timestamp04);
    $month  substr($timestamp42);
    $day    substr($timestamp62);
    $hour   substr($timestamp82) - 6;
    $minute substr($timestamp102);
    $second substr($timestamp122);

    $new mktime($hour$minute$second$month$day$year);
    echo 
    date('Y M d H i s'$new); 
    btw: The month will be September.

    However, you can also format the time directly in the query

    Code:
    SELECT DATE_FORMAT(datecolumn, '%Y %M %d %H %i %s') AS 'somedate' FROM sometable;

  4. #4
    SitePoint Zealot
    Join Date
    Jan 2002
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    really..hmm.ok i think i might use it that way, because instead, i went like this:
    PHP Code:
    $date date('Ymd');
    $time time() + 3600*18/*to compensate timezones*/
    $timestamp $date date('His',$time); 
    InQuE


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
  •