Joyride Posted November 8, 2006 Report Share Posted November 8, 2006 Situacija ir sekojosa, ir sludinajuma pievienosanas forma, kura viens no elementiem ir t.s. deadline combobox, kura lietotajs izvelas, cik ilgi sludinajumu radit. Tad, kad lietotajs nosuta sludinajumu pievienosanai, skripts sanem infu par terminu: switch($deadline) { case '3d': // 3 dienas break; case '1n': /* 1nedela */ break; case '2n': /* 2 nedelas*/ break; case '3n': /* 3nedelas */ break; case '1m': /* viens menesis */ break; default: /* piem, 3 dienas */ break; } Jautajums ir tads, ka visvienkarsak ir mysql datubaze saglabat sludinajuma datumu (sodienas + tas termins, cik lietotajs ir izvelejies)? Atradu, ir erti izmantojama MySQL DATE_ADD() funkcija. Varbut kadam noderes: http://dev.mysql.com/doc/refman/5.0/en/dat...-functions.html Link to comment Share on other sites More sharing options...
andrisp Posted November 8, 2006 Report Share Posted November 8, 2006 http://dev.mysql.com/doc/refman/5.0/en/dat...-functions.html Vispār to var izdarīt visādos veidos, bet lūk viens variants no manuāļa: DATE_ADD('1999-01-01', INTERVAL 'pievienojamo_dienu_skaits' DAY); Link to comment Share on other sites More sharing options...
Joyride Posted November 8, 2006 Author Report Share Posted November 8, 2006 Paldies, tas ir tiesi tas, kas man ir vajadzigs! Link to comment Share on other sites More sharing options...
Kavacky Posted November 8, 2006 Report Share Posted November 8, 2006 (edited) Man labāk patīk timestampi: time() + $dienas * ( 24 * 60 * 60 ); // Iekavās gan sareizini pats, lai katru reizi tas nav jāatkārto Edited November 8, 2006 by Kavacky Link to comment Share on other sites More sharing options...
andrisp Posted November 8, 2006 Report Share Posted November 8, 2006 (edited) Var jau arī: FROM_UNIXTIME(UNIX_TIMESTAMP('1997-10-04') + ([dienu_skaits] * 24 * 60 * 60)); :) Edited November 8, 2006 by andrisp Link to comment Share on other sites More sharing options...
Gundars Posted November 8, 2006 Report Share Posted November 8, 2006 (edited) Nu nezinu, kapēc būtu jaizmato tur Sql funkcijas. Shados gadījumoe ir PHP vienkarhsi uztaisāms: strtotime ( string time [, int now] ) switch (..) { case '1n' $endate = date('+1 week',$currentdate);break; case '2n' $endate = date('+2 week',$currentdate);break; default: $endate = date('+3 days',$currentdate);break; } Edited November 8, 2006 by Gundars Link to comment Share on other sites More sharing options...
andrisp Posted November 8, 2006 Report Share Posted November 8, 2006 Tik pat labi varētu pateikt otrādi, kāpēc izmantot php fjas, ja var iztikt ar mysql fjām. Nedomāju, ka tavs piemērs strādātu diži ātrāk. Link to comment Share on other sites More sharing options...
Delfins Posted November 8, 2006 Report Share Posted November 8, 2006 Ar tiem datumiem vispār ir čakars... unixtime ta no 1970 skaitās.. A vot kā tu pieplusosi pie 1799 (Puškina dz.gads) ?? Moš kāds i ir uztaisījis f-ju, kas pluso klāt N-xyz pie yyyy-mm-dd... Jāpaskatās. Link to comment Share on other sites More sharing options...
Recommended Posts