Creating a date relative to the current

In PHP it were a standard way of storing information about the date of the aforementioned timestamp format. Modifications of such a recording is performed by adding or subtracting the appropriate number of seconds.

For example, to create a date for an hour in front of the current, just add it to 3,600 seconds, or as much as a second in time.
Example

<?php

$current_time= time ();
$per_hour = $current_time + 3600;
echo date ( „r”, $per_hour);                  // Displays the date ‚per hour’

?>

The same thing seems to adding days or weeks. It is worse for months – after all, it is not known in advance how many seconds a month. This problem can be solved in several ways team task management. You can break up the date for individual parts (day, month, year), add the number one to the month, see if he left us thirteenth month (what happens if we add a month to December) and in this case the appropriate response.

Example

<?php

$day = date (‚d’);                        // day
$month = date (‚m’);              // month
$year = date (‚Y’);                   // year

// Adding one to the month
$month ++;

// Check if the meter is not turned
if ($month == 13) {
$month = 1;
$year ++;
}

?>

You can either use the strtotime (). As the argument can be specified relative time.
Example

<?php

echo strtotime („now”), „\ n”;                     // now
echo strtotime („+ 1 day”), „\ n”;              // tomorrow
echo strtotime („+ 1 week”), „\ n”;               // next week
echo strtotime („+ 1 week 2 days 4 hours 2 seconds”), „\ n”;         // Per week, two days,
// 4 hours and 2 seconds
echo strtotime („next Thursday”), „\ n”;                      // Next Thursday
echo strtotime („last Monday”), „\ n”;                     // Previous Monday

?>

 

Cookies help us deliver our services. By using our services, you agree to our use of cookies. More Info | Close