Add some specific dates to some date

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghjk
    Contributor
    • Jan 2008
    • 250

    Add some specific dates to some date

    In my web application user should register a date and the validity period(ex.5 days). So when user logging i want to check whether his account expired. To do that i want to add validity period to the user registered date? how can i do that? Some forum says to use "mktime". But still i couldn't do that. Could you please help me?
  • coolsti
    Contributor
    • Mar 2008
    • 310

    #2
    What do you mean that you could not do that? What have you tried?

    I assume you are using a database to store the user information, and as an alternative, you could let the database do the date calculations for you. If you are using MySQL, date manipulations are rather easy using mysql functions. So when a user registers, you can either insert the current date into the user information table (alternatively, you can already add 5 days when doing this insert and store the user's expiration date directly). And when the user tries to log in, you can use a query comparing the current date against the date stored in the database to see if the expiration date has been past. Using the database's date functionalities may be more intuitively easier to use (depending on the database) but you could do this either way, either in PHP or using the database.

    Comment

    • ghjk
      Contributor
      • Jan 2008
      • 250

      #3
      I have done it.
      [PHP]
      list($year, $month, $day) = split('[/.-]', $Valid_From);
      $daystoadd="$Va lidity_Period";
      $hours=$daystoa dd * 24;
      $newdate=date(" Y-m-d", mktime($hours, 0, 0, $month, $day, $year));
      //echo "The new date is: " . $newdate."'";
      if($newdate < $today)
      {
      echo "expierd";
      }
      else
      {
      echo "ok";
      }
      [/PHP]
      Last edited by Atli; May 15 '08, 03:29 AM. Reason: Removed the 5 tab prefix on each line.

      Comment

      • TheServant
        Recognized Expert Top Contributor
        • Feb 2008
        • 1168

        #4
        So this has been solved?

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          It looks like it is solved, TheServant.
          But I am really curious as to why OP does not use the (easier) MySQL routines to achieve his/her goal. A simple SQL command like DATE_ADD() or DATE_DIFF() would have done it. But who am I to guess?

          Ronald

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Yea, it would be much simpler to use the MySQL functions to do this kind of stuff.

            Like say... using the DATEDIFF function with the NOW function and your date column.

            Comment

            Working...