lazda144 Posted August 7, 2008 Report Share Posted August 7, 2008 Vai var atnemt laiku no esoshaa date? Mna formaats ir date('Y-m-d H:i:s') un vajag atnemt 30 sec Link to comment Share on other sites More sharing options...
cucumber Posted August 7, 2008 Report Share Posted August 7, 2008 (edited) sasplito ieliec mktim'a , no iznakuma atnem 30, tad atkal atpakal uztaisi caur date( mktime) un formatu. ps. laikam kretiniski uzraksitju function timeSub($formatOut = "Y-m-d H:i:s", $secInterval = 30 ) { list($y,$m,$d,$h,$i,$s) = explode("-" ,date('Y-m-d-H-i-s')); $newTime = mktime($h, $i, $s, $m,$d,$h, $y) - $secInterval; echo date($formatOut,$newTime); } echo date('Y-m-d H:i:s'); timeSub(); 2008-08-08 00:14:39 2000-08-08 00:14:09 Edited August 7, 2008 by cucumber Link to comment Share on other sites More sharing options...
Mr.Key Posted August 7, 2008 Report Share Posted August 7, 2008 Nu jau drīz varēs izmantot sekojošu funkciju: date_add() / DateTime::add(), date_sub() / DateTime::sub() for applying an interval to an existing date/time. http://www.php.net/manual/en/function.date-add.php http://www.php.net/manual/en/function.date-sub.php Link to comment Share on other sites More sharing options...
cucumber Posted August 7, 2008 Report Share Posted August 7, 2008 This function should be used at your own risk. (: gaidam 6'to Link to comment Share on other sites More sharing options...
xPtv45z Posted August 8, 2008 Report Share Posted August 8, 2008 Var jau daudz vienkāršāk - $newDate = date('Y-m-d H:i:s', strtotime($esoshais)-30); Bet ja jau no esošā, tad vispār - date('Y-m-d H:i:s', time()-30) Un cucumber tavs variants nestrādās, jo tomēr ir mazliet atšķirība list($y,$m,$d,$h,$i,$s) = explode("-" ,date('Y-m-d-H-i-s')); no Mna formaats ir date('Y-m-d H:i:s') Link to comment Share on other sites More sharing options...
cucumber Posted August 8, 2008 Report Share Posted August 8, 2008 to:xPtv45z nav atshkiribas, tak f-ja ir parametrs $formatOut = "Y-m-d H:i:s", kas ari dot 2008-08-08 00:14:39 pec formata Link to comment Share on other sites More sharing options...
xPtv45z Posted August 8, 2008 Report Share Posted August 8, 2008 Jā, es mazliet pārpratu tavu kodu. Bet tik un tā tur ir diezgan bezjēdzīga darbība. :) Priekš kam vēl splitot, ja uzreiz var iegūt timestamp, tas kas tev funkcijā ir uzrakstīts 3jās rindiņās ir uzrakstāms vienā return date($formatOut, time()-$secInterval); Link to comment Share on other sites More sharing options...
cucumber Posted August 8, 2008 Report Share Posted August 8, 2008 par to nestrido (:, vels jau bija function timeSub($formatOut = "Y-m-d H:i:s", $secInterval = 30 ) { return date($formatOut, time()-$secInterval); } // nice Link to comment Share on other sites More sharing options...
Recommended Posts