Jump to content

date calculations advice


Ninjakreborn

Recommended Posts

Ok, I am getting the date like this

$date = strtotime(date());

ok, there you have it, a Unix time stamp of the time, date, and everything else.

From here, is this the best way to do calculations.

Like if I wanted to tell when 48 hours had passed from this date, how do I go about doing that.

I know for example if you wanted to add a day, you check on how many "number's" here are in a day and put + that number onto the strength.

Can someone tell me some stuff about this, so I am more familiar with dates, before I start all of these calculations.

 

Link to comment
https://forums.phpfreaks.com/topic/47284-date-calculations-advice/
Share on other sites

$date = time()+3600*24*2;

 

The unix timestamp goes by seconds. That is a more effective and reliable way of getting a time stamp. Now if you want to do calculations later this might help

 

$date = time();

$newDate = time()+3600*24*2;

 

But yes timestamps are the best way to manipulate time. Very simple as seen above.

strtotime() has some powerful features for adding to times

<?php
$now = time();

echo 'Now :', date ('jS M Y H:i:s', $now), '<br>';

echo 'Now + 48 hours : ', date ('jS M Y H:i:s', strtotime('+48 hours', $now)), '<br>';

echo 'Now + 7 days : ', date ('jS M Y H:i:s', strtotime('+7 days', $now)), '<br>';

echo 'Next Sunday : ', date ('jS M Y H:i:s', strtotime('next sunday')), '<br>';


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.