SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru Nick Carlson's Avatar
    Join Date
    Aug 2003
    Location
    Denver
    Posts
    644
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problems with time(), very confused.

    I'm writing a stats script that tracks pageviews and clicks on links. Each page view and click is recorded with and offsetted time().

    My problem is this, I need a reverse function for time(). When I use time(), it puts a date in like this "1100943606". Very unfriendly. I need to be able to take any date (like november 2nd, 2004), and find out what the string of numbers is at 12:00:00am on that date, and what the string of numbers is on 11:59:59pm on that date.

    Is there any way to do this? Can someone point me in the right direction?

    Thank you so much.
    ncarlson.net - a programmer's dystopia

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,449
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    str_to_time()

    This takes a string like 'november 2nd, 2004' and makes a Unix timestamp. Basically, it can take various different strings and return a timestamp. That page should give you decent tips on how to use it. If you want the reverse of that, use date().

  3. #3
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Look at:

    mktime ()

    date()

  4. #4
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,449
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by arborint
    Look at:

    mktime ()

    date()
    PHP sure does have plenty of time functions.

  5. #5
    SitePoint Guru Nick Carlson's Avatar
    Join Date
    Aug 2003
    Location
    Denver
    Posts
    644
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you both for your help.

    I think mktime() is what I need. I've been working on this stats part of my script for weeks. It's just a pain in the ***. I hate heavy coding like this. (well, heavy to me anyways.)

    Thanks again.
    ncarlson.net - a programmer's dystopia

  6. #6
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    Abilene, TX
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The time function is the best function you should use for storage as time() records time in what is known as Epoch time (or the number of second that have past Epoch - Midnight January 1, 1970). This number represents the exact date and time of that instance. I would store the data in your DB (if you are using a DB) in this format and make it readable when you need it.

    Here are some examples for you:

    To output date as "November 30, 2004 at 10:55 pm":

    PHP Code:
    $date date("F j, Y at g:i a"time());
    echo 
    "$date"
    Reg

    "I don't care how many beers you've had...
    Get your chickens out of my lawn!"


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
  •