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.

Link to comment
Share on other sites

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!

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.