AV1611 Posted February 2, 2008 Share Posted February 2, 2008 I can't seem to think straight today. I need to do two things: convert a unix timestamp to human readable: for example, if I have UNIX time 1201976015 I want it do output 02/02/2008 6:13pm GMT. I can write the script, I just can fire out the function Second: For a given day/month/year, what's the function to output the unix time for +7 days? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/89098-noob-time-question/ Share on other sites More sharing options...
pocobueno1388 Posted February 2, 2008 Share Posted February 2, 2008 For your first question <?php //Unix Timestamp $time = time(); //Convert $date = date("Y-m-d g:i", $time); echo $date; ?> And for your second: <?php //Unix Timestamp $time = time(); //Convert and add 7 days $date = date("Y-m-d g:i", strtotime("$date + 7 DAY")); echo $date; ?> Quote Link to comment https://forums.phpfreaks.com/topic/89098-noob-time-question/#findComment-456333 Share on other sites More sharing options...
AV1611 Posted February 2, 2008 Author Share Posted February 2, 2008 See any problem here? <?php $ut= strtotime("+1 week"); echo $ut; //gives me the unix time of 1 week from this second of time echo "<br />"; $date=getdate($ut); echo $date['month'].' '.$date['mday'].' '.$date['year'];//gives me the date of the above timestamp (I do not care about time) ?> Quote Link to comment https://forums.phpfreaks.com/topic/89098-noob-time-question/#findComment-456334 Share on other sites More sharing options...
pocobueno1388 Posted February 2, 2008 Share Posted February 2, 2008 Well, if it works then thats fine. Or you could do it this way <?php $ut= strtotime("+1 week"); echo date("Y-m-d", $ut); ?> Quote Link to comment https://forums.phpfreaks.com/topic/89098-noob-time-question/#findComment-456342 Share on other sites More sharing options...
AV1611 Posted February 3, 2008 Author Share Posted February 3, 2008 I am really asking two different questions, but it seems to be answered here. The system I am working with uses unix time, but I have to create a form that uses a point of time in the future, so I need to use human dates in the form but unix time in the output to a .csv file. Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/89098-noob-time-question/#findComment-456504 Share on other sites More sharing options...
pocobueno1388 Posted February 3, 2008 Share Posted February 3, 2008 Well, the code I gave you will convert it to how you want, I'm not really sure what else your trying to do. Or did you get it to work? Quote Link to comment https://forums.phpfreaks.com/topic/89098-noob-time-question/#findComment-456506 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.