StirCrazy Posted November 11, 2006 Share Posted November 11, 2006 Hi folks,just a quick question ~what's the php code to echo exactly 9 months (for point of echo) in a Unix timestamp format?Thanks,S.C> Quote Link to comment Share on other sites More sharing options...
AndyB Posted November 12, 2006 Share Posted November 12, 2006 Exactly nine months is a different number of seconds depending on the start and finish month, as months have different numbers of days.Do you want nine months from today's date into the future ... or what? Quote Link to comment Share on other sites More sharing options...
StirCrazy Posted November 12, 2006 Author Share Posted November 12, 2006 good point :D ~ ok, it's to work out pregnancy times, so 280 days :)S.C> Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 12, 2006 Share Posted November 12, 2006 The following is copied from www.php.net/time:[code]<?php$nextWeek = time() + (7 * 24 * 60 * 60); // 7 days; 24 hours; 60 mins; 60secsecho '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; 60secsecho '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-11280 Days: 2007-08-18[/quote] Quote Link to comment Share on other sites More sharing options...
StirCrazy Posted November 12, 2006 Author Share Posted November 12, 2006 Thanks Don. What would I need to do to that code to make it into the timestamp?S.C> Quote Link to comment Share on other sites More sharing options...
Nicklas Posted November 12, 2006 Share Posted November 12, 2006 280 days into the future from now[code]<?phpecho 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]<?phpecho 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]<?phpecho strtotime("+280 days");?>[/code]Or[code]<?phpecho strtotime("2006-11-01 +280 days");?>[/code] Quote Link to comment Share on other sites More sharing options...
StirCrazy Posted November 12, 2006 Author Share Posted November 12, 2006 thanks ;Done 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. Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 13, 2006 Share Posted November 13, 2006 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 Quote Link to comment Share on other sites More sharing options...
Nicklas Posted November 13, 2006 Share Posted November 13, 2006 to convert it back to a string, all you have to do, is something like this:[code=php:0]$decimal = "8571428571";$rdays = '' . $decimal / "14.285714285";echo $rdays[0]; // print first char: 6[/code] Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 13, 2006 Share Posted November 13, 2006 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]Line16Line2[/quote] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.