Subtracting and adding to current date then turn into timestamp

Posted on 2009-04-22
Last Modified: 2012-05-06
Hi all,

I have to take the current time and date, and I have to add it 9 hours and subtract 3 minutes and also subtract 7 seconds.
Then I have to turn the result into a timestamp.

For example, let's say that the current time is 10 hours 3 minutes and 7 seconds and the date is today's date.
I need it to be 19 hours 0 minutes and 0 seconds of today's date and I have to turn that into a timestamp.

How can I do it?
Thanks a ton in advance!
Question by:Dada44
    LVL 19

    Expert Comment

    why try all math before converting?

    $answer = time() + 9 * 3600 - 3 * 60 - 7;

    Author Comment

    sorry but converting the timestamp I get is: Thu, 23 Apr 2009 03:02:36 +0200
    and it should be  Thu, 22 Apr 2009 18:03:36 +0200
    LVL 19

    Accepted Solution

    Do you need local (server) time? GMT? or Clients time?

    $answer = time();
    echo "Now : ". date("M j G:i:s T Y", $answer) ."<br />\n";
    $answer = $answer + 9 * 3600 - 3 * 60 - 7;
    echo "Then: ". date("M j G:i:s T Y", $answer) ."<br />\n";
    Now : Apr 22 9:21:54 MST 2009
    Then: Apr 22 18:18:47 MST 2009

    Open in new window


    Author Closing Comment


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    As this topic comes over and over again in different forms, I've finally decided to write a short (yea, right...) article / tutorial about pagination with PHP with MySQL database. There are dozens of these kind of tutorials, I know - I wanted to mak…
    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    The viewer will learn how to count occurrences of each item in an array.
    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.

    728 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

    20 Experts available now in Live!

    Get 1:1 Help Now