Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
190 views
in Technique[技术] by (71.8m points)

php - How to Subtract Minutes

I want to send a reminder email.I don't want to use cron on Linux/Unix/BSD box or Scheduled Tasks on Windows.

I'm trying to subtract 15 minutes from the current time.

here is my code so far (doesn't work):

$days   = date("j",time());
$months = date("n",time());
$years  = date("Y",time());
$hours  = date("G",time());
$mins   = (date("i",time()));
$secs   = date("s",time());
$mins   = $mins-15;
question from:https://stackoverflow.com/questions/17717911/how-to-subtract-minutes

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Change the date into a timestamp (in seconds) then minus 15 minutes (in seconds) and then convert back to a date:

$date = date("Y-m-d H:i:s");
$time = strtotime($date);
$time = $time - (15 * 60);
$date = date("Y-m-d H:i:s", $time);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...