lazda144 Posted August 7, 2008 Report 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
cucumber Posted August 7, 2008 Report 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
Mr.Key Posted August 7, 2008 Report 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
cucumber Posted August 7, 2008 Report Posted August 7, 2008 This function should be used at your own risk. (: gaidam 6'to
xPtv45z Posted August 8, 2008 Report 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')
cucumber Posted August 8, 2008 Report 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
xPtv45z Posted August 8, 2008 Report 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);
cucumber Posted August 8, 2008 Report 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
Recommended Posts