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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.