Jump to content

[SOLVED] formatting current date & time as: 2006-04-12 13:47:36 and substract 15 minutes


angelcool

Recommended Posts

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.

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!

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.