-1

I'd like to take a number of hours imputed in a text box and get a timestamp back so I can create a countdown timer.

The countdown is fine so ignore how that is done etc. But whats the best way to get a timestamp '48' hours from now. For example user has entered 48?

Steviehype
  • 71
  • 5
  • 15
  • 3
    Google "datetime add hours php" which you may very well land on one of [**John Conde's answer**](http://stackoverflow.com/a/15228865/) – Funk Forty Niner Jun 24 '14 at 14:51

3 Answers3

1

You can create a timestamp like this:

<?php
strtotime(date('d-m-Y H:i:s') . "+ 48 hours");
?>
Daan
  • 12,099
  • 6
  • 34
  • 51
1
$hours = 48;
$timestamp = (new DateTime())->modify("+{$hours} hours")->format('U');
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • [`I plugged ya`](https://stackoverflow.com/questions/24389744/php-get-timestamp-x-hours-from-now#comment37722862_24389744) ;-) – Funk Forty Niner Jun 24 '14 at 14:53
  • You shot me? ;) Didn't realize it was a dupe. Closing this one as a dupe of the other one. – John Conde Jun 24 '14 at 14:54
  • Au contraire mon frère. Around here, "to plug" means to "tell people of one's good work" ;-) http://dictionary.reference.com/browse/plug *"a free advertisement or a commercial boost from someone for a product. (See also plugola.) : I managed to get a plug on the Mike Michael show. tv."* – Funk Forty Niner Jun 24 '14 at 14:56
  • I knew what you meant. I guess being Italian and from New York the other one always springs to mind. :) – John Conde Jun 24 '14 at 14:58
  • *Holding up Wile E. Coyote's **YIPES!** sign* – Funk Forty Niner Jun 24 '14 at 14:59
  • Thanks. I did search but as the answer was out of my mind set I missed that you could just `+ X hours`. – Steviehype Jun 24 '14 at 16:20
1

Your looking for strtotime. For example, you can just use strtotime('+48 hours'), and it will return a unix timestamp for that time.

MrGlass
  • 9,094
  • 17
  • 64
  • 89