angelcool Posted November 13, 2008 Share Posted November 13, 2008 Hello community, I want to format PHP date and time to: 2006-04-12 13:47:36 and then substract 15 minutes, so the final result will be: 2006-04-12 13:32:36 I'm away home, so I cannot test this since I do not have my vbox fedora server, but cannot wait to get the right code; after all I guess I am php freak. :-) So far I got this to format the current date & time, but do not know if correct (no tested): $current_time=date("Y-n-j, G:m:s"); I still have to figure out how to substract 15 minutes. I will apreciate any help. Thank you, Angel. Quote Link to comment https://forums.phpfreaks.com/topic/132519-solved-formatting-current-date-time-as-2006-04-12-134736-and-substract-15-minutes/ Share on other sites More sharing options...
JasonLewis Posted November 13, 2008 Share Posted November 13, 2008 You can use strtotime to subtract a certain amount of time. echo date("h:i:s", strtotime("-15 Minutes")); Quote Link to comment https://forums.phpfreaks.com/topic/132519-solved-formatting-current-date-time-as-2006-04-12-134736-and-substract-15-minutes/#findComment-689110 Share on other sites More sharing options...
angelcool Posted November 13, 2008 Author Share Posted November 13, 2008 Bingo! Here is the code to get what I needed: <?php //Right now date and time. Format: 2008-11-13 3:12:33 echo '<b>Date and Time when this page was fetched from server:</b><br>'.date("Y-n-j G:i:s"); //15 minutes ago date and time: Format:2008-11-13 2:57:33 $past_time = date('Y-n-j G:i:s', mktime(date('G'),date('i')-15,date('s'), date('m'), date('d'), date('Y'))); echo '<br><br><b>The Date and Time 15 minutes before this page was fetched from server is:</b><br>'.$past_time; ?> Hope this helps anyone who will need it. Good luck! Quote Link to comment https://forums.phpfreaks.com/topic/132519-solved-formatting-current-date-time-as-2006-04-12-134736-and-substract-15-minutes/#findComment-689141 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.