mám tento kod
<?
include "config.php";
$query=mysql_query("select *,DATE_FORMAT(datum,'%d.%m.%Y') as datum from
evidence order
by id DESC LIMIT 0,20");
while ($zaznam=mysql_fetch_array($query)):
$date=$zaznam["datum"];
$p=explode(".",$date);
$den=$p[0];
$mesic=$p[1];
$rok=$p[2];
?>
a potřebuji aby mě to vypsalo např. Středa, 20. června 2007. Pomocí explode jsem
si řetěž rozdělil, ale už nevím jak mám dál, sice mě napadlo, že bych mohl
použít str_replace, ale to by bylo asi hodně zdlouhavé. Určitě existuje nějaké
lepší řešení. Prosím o radu..dík
Fórum › PHP
Datum

vytvor si pole dnu :
$dny[0]="pondeli";
........
potom si zjisti mktime() tvyho data
$cas=mktime(0,0,0,$mesic,$den,$rok);
a potom si dej zjistit fcí date() index dne :
$den=date("w",$cas);
echo $dny[$den];
Je to psaný na rychlo ! takže doufam že to mam dobře !
Pripomienka:
"select *,DATE_FORMAT(datum,'%d.%m.%Y') as datum
..vrati result v ktorom budes mat stlpec datum dva-krat. Ked z neho vytvoris pole (mysql_fetch_array()), tak pod indexom datum uz budes mat iba udaj (z posledneho stlpca) Ciselne indexy sa zachovaju. (...trocha pakaren).
[podtrzene]Postup, toho, co vlastne chces je takyto:[/podtrzene]
1. potrebujes z db dostat datum (SELECT from...)
2. potrebujes vypocitat UNIX_TIMESTAMP - cas aky pouziva PHP ([podtrzene]don_Dominique[/podtrzene] pouzil mktime())
3. potrebujes vypisat tento cas v pozadovanom tvare.
body 1 a 2 sa daju jednoducho spojit:
Z databazy mozes vyberat datum priamo v unixovom tvare, usetris tak cas a pracu php-cku:
SELECT UNIX_TIMESTAMP(datum) as ux_time...
Problem moze sposobit posuvanie casovych zon v MySQL, UNIX_TIMESTAMP('1970-01-01 00:00:01') nemusi vratit 1 (datum sa najprv prevedie do gtm a az tak sa pocita timestamp), preto, ak si niesi isty, existuje univerzalne riesenie:
SELECT UNIX_TIMESTAMP(CONVERT_TZ(datum, '+0:00', 'SYSTEM')) as ux_time
[podtrzene]k bodu 3 mas 2 moznosti:[/podtrzene]
3.1. nastavit jazyk pre fciu date() a uz len vypisat. -- najjednoduchsia moznost
3.2. Rozlozit timestamp na casti (rok, mesiac, den, den v tyzdni,...) a postupne vypisat.
3.1.) Zavolas setlocale(LC_TIME, 'cs'); a fcia date() bude vypisovat vsetko v cestine... (zalezi ci system cestinu podporuje)
3.2.) definujes si pole dni a mesiacov, ako navrhol [podtrzene]don_Dominique[/podtrzene]:
$dni = Array('pondelok','utorok','streda',...);
$mesiace = Array(1=>'januar', 'februar', 'marec', ...); // indexovanie od 1 (inak by bolo od 0)
a jednoducho vypisujes:
echo $dni[date('w',$timestamp)].', '.
date('j',$timestamp).'. '.
$mesiace[date('n',$timestamp)].' '.
date('Y',$timestamp);
[podtrzene]Priklad s pouzitim setlocate:[/podtrzene]
setlocale(LC_TIME, 'cs');
$t=MySQL_query("SELECT UNIX_TIMESTAMP(CONVERT_TZ(datum, '+0:00', 'SYSTEM')) as ux_time FROM ...");
while($r = MySQL_fetch_assoc($t))
{
..
echo date( 'l, j. F Y', $r['ux_time'] );
..
}
MySQL_free_result($t);
http://www.php.net/setlocale
http://www.php.net/date
http://dev.mysql.com/doc/refman/4.1/en/time-zone-support.html
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_unix-timestamp
déjà vu, alebo ľudská lenivosť je nekonečná?
piaty príspevok pod týmto: http://www.programujte.com/forum.php?akce=prispevek&id=5002&sekce=datum-cesky
To OndreJ: lol, skor to druhe ;-)
V tomto vlakne chceme vypisat "...např. [podtrzene]S[/podtrzene]tředa, 20. června 2007", pričom pred tym "...např. [podtrzene]s[/podtrzene]tředa, 20 června 2007"
...takze ake dejavu, ved tam je rozdiel ?!
Nějak mi to nefunguje. Mohl by mi prosím někdo zkusi propojit uvedený skript s tímto:
<?
include "config.php";
$query=mysql_query("select *,DATE_FORMAT(datum,'%d.%m.%Y') as datum from
evidence order
by id DESC LIMIT 0,20");
while ($zaznam=mysql_fetch_array($query)):
$date=$zaznam["datum"];
$p=explode(".",$date);
$den=$p[0];
$mesic=$p[1];
$rok=$p[2];
?>

Přidej příspěvek
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
































Uživatelé prohlížející si toto vlákno
Podobná vlákna
Moderátoři diskuze