Need help with date();

Discussion in 'PHP' started by mab, Feb 27, 2008.

  1. #1
    Hello guys ..

    i want to learn some skills in date();
    like someone his date birth is 1991/01/01 and today we are 28/02/2008 ..
    i want to echo 17 years old :) ..
    hmm another idea like some members registered today i want to retrieve their data from mysql . i mean last 24H members how ?

    if anyone can give me the main idea or tell me where can i got this ill be glad :)
    Thanks in advance .
     
    mab, Feb 27, 2008 IP
  2. in2clearsky

    in2clearsky Peon

    Messages:
    121
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    in2clearsky, Feb 28, 2008 IP
  3. mab

    mab Active Member

    Messages:
    563
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    80
    #3
    thank you .. its kinds complicated .. hmm it didn't work
     
    mab, Feb 28, 2008 IP
  4. mab

    mab Active Member

    Messages:
    563
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    80
    #4
    Still looking for help guys :(
     
    mab, Mar 1, 2008 IP
  5. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #5
    First one:
    $yr = 1991;
    $year =date('Y');
    $age = $yr - $year;
    echo $age;

    Leave it up to you to add checking the month to determine if they are +/-.

    Second one could use mktime(). Push it back by a day, take the timestamp and compare to the time stamp in the database.


    $yesterday = mktime(0, 0, 0, date("m") , date("d")-1, date("Y"));
    $today = mktime(0,0,0);
    $dif = $today - $yesterday;

    last two lines are just a double check. A day is 60*60*24 or 86400. Which you could just subtract from mktime(0,0,0); Then use that to compare against the db.
     
    shallowink, Mar 1, 2008 IP
    mab likes this.
  6. mab

    mab Active Member

    Messages:
    563
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    80
    #6
    Thank you brother very much for your help and time .. i really appreciate this .
    Rep +
     
    mab, Mar 2, 2008 IP