Change value of time

Posted on 2011-04-25
Last Modified: 2012-05-11
Hi all,

I have a php script that has this line of code:

$expire = time()+(30*24*3600);

From what I understand this sets the $expire to a date that 30 days from current time.

What do I need to do to change it so that it becomes 90 days from a date that is 30 days prior to current date?

For example
Today's date  = 26/04/2011
Expiry date = 26/03/2011 + 90 days = 26/06/2011

Question by:AnuarJamlus
    LVL 1

    Author Comment

    Didn't realise everyone is givign away 500 points...  Adding additional points to this question.
    LVL 1

    Author Comment

    Hmmm...  ok... still not 500 points. Guess this should do it...
    LVL 2

    Expert Comment

    Hi AnuarJamlus.
    here is a ref.

    it shows how to play with date function in php
    LVL 12

    Expert Comment

    As the link provided by vogen points out, mktime is typically used for messing around with arbitrary dates.

    But as for your code, it's using the time() function to calculate the number of seconds since the "unix epoch",
    and adding 30 days * 24 hours/day * 3600 seconds/hour.
    (see also

    To adjust that as desired, note that "90 days from a date that is 30 days prior to current date" is just 60 days from now (if I understood you correctly),
    so you could just change it to:
      $expire = time()+(60*24*3600);
    LVL 1

    Author Comment

    Yes I guess that is one way to look at it.

    I guess what I am really looking for was a way to deduct from a time then add to that time. Is it possible to do a time() - (60*24*3600); to get a time that is 60 days in the past?
    LVL 12

    Accepted Solution

    Absolutely.  time(), being simply a count of seconds since the epoch, is just a big integer.  You can subtract (60*24*3600) from it just fine.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now