Ninjakreborn Posted April 16, 2007 Share Posted April 16, 2007 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 More sharing options...
per1os Posted April 16, 2007 Share Posted April 16, 2007 $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. Link to comment https://forums.phpfreaks.com/topic/47284-date-calculations-advice/#findComment-230646 Share on other sites More sharing options...
Barand Posted April 16, 2007 Share Posted April 16, 2007 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>'; ?> Link to comment https://forums.phpfreaks.com/topic/47284-date-calculations-advice/#findComment-230767 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.