SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: time()

  1. #1
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    time()

    When I use time() I prints out like 9 or so numbers, how does that actually relate to the time it was done?

  2. #2
    The Jellophonic Autobrain CHeeSeBLiND's Avatar
    Join Date
    Jul 2001
    Location
    Bolton, England
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
    hmm...

  3. #3
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might want this one: http://php.net/date , and customize it to display just what you want to see

    Off-topic, but still related to date() :
    PHP Code:
    function mysql2date($dateformatstring$mysqlstring) {
        
    $m $mysqlstring;
        
    $i mktime(substr($m,11,2),substr($m,14,2),substr($m,17,2),substr($m,5,2),substr($m,8,2),substr($m,0,4)); 
        
    $i date($dateformatstring$i);
        return 
    $i;

    This is a quick function I made to deal with MySQL's default timestamp format (yyyy-mm-dd hh-mm-ss). You just use it like date(), only the second argument is a mysql timestamp instead of a unix timestamp.
    Hope this helps

  4. #4
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    whats the Unix Epoch ?

  5. #5
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A date that's been arbitrary chosen as the start when counting the time with seconds. Think of it as Jesus Christ's birth time, for modern believers
    Counting the time universally in seconds has its advantages, one of those being that you can then treat the number as you wish in the quickest way, unlike the complicated calculations that you'd have to do on a hh:mm:ss time to convert it to another format, for example.

  6. #6
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Shin Ma
    PHP Code:
    function mysql2date($dateformatstring$mysqlstring) {
        
    $m $mysqlstring;
        
    $i mktime(substr($m,11,2),substr($m,14,2),substr($m,17,2),substr($m,5,2),substr($m,8,2),substr($m,0,4)); 
        
    $i date($dateformatstring$i);
        return 
    $i;

    This is a quick function I made to deal with MySQL's default timestamp format (yyyy-mm-dd hh-mm-ss). You just use it like date(), only the second argument is a mysql timestamp instead of a unix timestamp.
    Hope this helps
    or you could just use MySQL's UNIX_TIMESTAMP() function:

    PHP Code:
    $r mysql_query('SELECT UNIX_TIMESTAMP(date_col) AS date FROM table'); 
    then just pass the value of the 'date' column to PHP's date() function. more effecient.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  7. #7
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's the number of seconds since 12:00:00am GMT, Jan 1, 1970
    Defender's Designs
    I'm Getting Married!

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


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
  •