PDA

View Full Version : Unos vremena u bazu


Gale
26-01-2006, 00:55
Koristim NOW() u MySQL-u za unos datuma u PHP skripti, ali vrijeme koje mi se unese je oko 7 sati razlike.

Da li ima tko kakav savjet kako da to riješim?

Hvala

administrator
26-01-2006, 02:30
Vecer,

par linkova o vremenima:
http://hr.php.net/time

i možda će Vam ovo pomoći:
http://hr.php.net/date

a posebno jedan od primjera navedan na tom linku:

<CODE>PHP date, strftime and mktime functions are DST sensitive
This means if the server is setup to be US GMT-5 and DST sensitive then the mentioned functions add, extract or do nothing with the current DST.

Without a given timestamp:
- date() uses the current server time.
This is DST affected if the server uses DST settings
- gmdate() uses the current GMT time, it extracts server GMT & DST.

With a given timestamp:
- date() is affected if the server uses DST settings
* if current time is DST but the given time isn't then DST is extracted
* if current time isn't DST but the given time is then DST is added
- gmdate() is affected, it extracts server GMT & DST on the given timestamp

So for example $timestamp is a GMT based time.
You modify the $timestamp for a "member" his personal timezone and dst.
The member has setup GMT-5 and DST sensitive
You add his GMT-5 to the $timestamp and check if the $timestamp is in DST or not

Then all the above functions are screwed in normal use.

<?php

$timestamp = 1122814800; // 07/31/05 13:00:00 GMT
$user_gmt = -5;
$user_dst = 1;

$timestamp += ($user_gmt*3600); // to user time
$timestamp += 3600; // user time is in DST

echo date("H:i:s",$timestamp);
echo gmdate("H:i:s",$timestamp);

?>

If server is GMT+0 in summer (DST is on) the above outputs

08:00:00
07:00:00

If server is GMT+0 in winter (DST is off) the above outputs
09:00:00
08:00:00

If server is GMT-5 in winter (DST is off) the above outputs
09:00:00
03:00:00

So if you work with local times and the server isn't GMT based be carefull how you output the times to your members. </CODE>
<CODE></CODE>
<CODE></CODE>
<CODE>pozdrav, SC</CODE>

administrator
26-01-2006, 02:39
dodatak:

ako može samo primjer koda Vašeg djela gdje kreirate varijablu za vrijeme kako bi Vam konkretno mogli pomoći.

pozdrav, SC

Gale
26-01-2006, 19:37
dodatak:

ako može samo primjer koda Vašeg djela gdje kreirate varijablu za vrijeme kako bi Vam konkretno mogli pomoći.

pozdrav, SC

Prilikom normalnog kreiranja INSERT querija u PHP-u za unos u bazu koristim NOW().

npr:


$sql= "INSERT INTO oglasnik (id, datum, vrsta) VALUES ('$id', NOW(), '$vrsta')";



hvala na odgovoru!

administrator
26-01-2006, 21:18
umjesto NOW funkcije možete napraviti ovo:
$today = getdate();
$order_date= $today['mday'].'.'.$today['mon'].'.'.$today['year'].' - '. $today['hours'] . ':' .$today['minutes'] . ':' .$today['seconds'].'h';

$sql= "INSERT INTO oglasnik (id, datum, vrsta) VALUES ('$id', '$order_date', '$vrsta')";

Samo je bitno da je dtum polje STRING ili LONG TEXT formata.

pozdrav, SC

Gale
26-01-2006, 22:26
umjesto NOW funkcije možete napraviti ovo:
$today = getdate();
$order_date= $today['mday'].'.'.$today['mon'].'.'.$today['year'].' - '. $today['hours'] . ':' .$today['minutes'] . ':' .$today['seconds'].'h';

$sql= "INSERT INTO oglasnik (id, datum, vrsta) VALUES ('$id', '$order_date', '$vrsta')";

Samo je bitno da je dtum polje STRING ili LONG TEXT formata.

pozdrav, SC




Probat ću, hvala.