help with months

i have created a site and it calculates the days since a user has logged in. But when the months changed the days since login got messed up. heres what it does.

$today = date('YmD');

$dsl = $today - $lastlogin;

$lastlogin = 20031130 and $today = 20031201 how could i fix this so when the months changed it does the calculation correctly

Comments

  • hmm...

    This is easiest to make with timestamp (it's an integer that counts the seconds starting from 1970's). Instead of using date() use time() to create a timestamp.
    [code]$lastlogin = time();[/code]

    Now you can just make a new timestamp when the user comes again to your page. With that timestamp you can count the seconds from the last login like this:
    [code]$count_seconds = time() - lastlogin();[/code]

    Then you just have to divide second count with 86400 (there are 86400 seconds in a day).
    [code]$days_from_last_login = round($count_seconds/86400);[/code]

    I hope I could help!
  • thanks that worked


    : hmm...
    :
    : This is easiest to make with timestamp (it's an integer that counts the seconds starting from 1970's). Instead of using date() use time() to create a timestamp.
    : [code]$lastlogin = time();[/code]
    :
    : Now you can just make a new timestamp when the user comes again to your page. With that timestamp you can count the seconds from the last login like this:
    : [code]$count_seconds = time() - lastlogin();[/code]
    :
    : Then you just have to divide second count with 86400 (there are 86400 seconds in a day).
    : [code]$days_from_last_login = round($count_seconds/86400);[/code]
    :
    : I hope I could help!
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories