Jump to content

unix timestamp


StirCrazy

Recommended Posts

The following is copied from www.php.net/time:
[code]
<?php
$nextWeek = time() + (7 * 24 * 60 * 60);
                  // 7 days; 24 hours; 60 mins; 60secs
echo 'Now:      '. date('Y-m-d') ."\n";
echo 'Next Week: '. date('Y-m-d', $nextWeek) ."\n";
?>
[/code]
So the following should give you 280 days from now:
[code]
<?php
$days280 = time() + (280 * 24 * 60 * 60);
                  // 280 days; 24 hours; 60 mins; 60secs
echo 'Now:      '. date('Y-m-d') ."\n";
echo '<br>280 Days: '. date('Y-m-d', $days280) ."\n";
?>
[/code]

I just ran that code and this is what my browser displayed:
[quote]
Now: 2006-11-11
280 Days: 2007-08-18
[/quote]
Link to comment
https://forums.phpfreaks.com/topic/26970-unix-timestamp/#findComment-123334
Share on other sites

280 days into the future from now
[code]<?php

echo date("Y-m-d", strtotime("+280 days"));

?>[/code]


add 280 days to a given date, ex starting from 2006-11-01 (good for countdowns etc)
[code]<?php

echo date("Y-m-d", strtotime("2006-11-01 +280 days"));

?>[/code]



To get the time in pure unixtime, just remove the surrounding date() function.

ex:
[code]<?php

echo strtotime("+280 days");

?>[/code]

Or
[code]<?php

echo strtotime("2006-11-01 +280 days");

?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/26970-unix-timestamp/#findComment-123338
Share on other sites

thanks  ;D

one more question.

$decimal = "8571428571";
$rdays = $decimal / "14.285714285";
$days = $rdays{0};

what am i doing wrong?
if I echo $days the answer should be 6... but it won't echo the first number?
($decimal changes but given an example).


any ideas?




or failing that, i need a function to convert 74304000 style timecodes into whole weeks and remaining days.
Link to comment
https://forums.phpfreaks.com/topic/26970-unix-timestamp/#findComment-123364
Share on other sites

I had the same problem when I tested it.  It seems that when the variable is a numeric value, it's not allowing you me to retrieve individual digits.  However whenever I concatenated a string onto the front it worked.

$decimal = "8571428571";
$rdays = $decimal / "14.285714285";
$rdays = "_" . $rdays;        //    <--add string to front.
echo $rdays[1];  //    <--grab SECOND character
Link to comment
https://forums.phpfreaks.com/topic/26970-unix-timestamp/#findComment-123760
Share on other sites

Nicklas,

I did that when I was testing his code.  NOTHING was sent to the browswer--not even an error message.

But the code that I posted DID work.

EDIT:  I don't know how to explain this one, but I put the following in a php file (all by itself) and uploaded it.  When I ran it, it worked.  I could swear that I had the same thing yesterday (looks the same to me).
[code]
<?php
$decimal = "8571428571";
$rdays = '' . $decimal / "14.285714285";
echo "<br />Line1<br>";
echo $rdays[0];
echo "<br />Line2<br>";
?>
[/code]

This is what my browser shows:
[quote]
Line1
6
Line2
[/quote]
Link to comment
https://forums.phpfreaks.com/topic/26970-unix-timestamp/#findComment-123940
Share on other sites

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.