Autor Beitrag
OliverN_26
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 252

Win7 64-Bit, WinXP SP3
Delphi 7 Enterprise
BeitragVerfasst: So 23.10.11 13:04 
Hallo

Da mir hier beim letzten Mal schon so gut geholfen wurde, hab ich noch einmal eine Frage, denn ich krieg es einfach nicht hin (MySQL).

Ich habe folgens Datum: Fri Sep 16 2011 13:00:00 GMT+0200
Das soll so aussehen: 2011-09-16 13:00:00

Danke :-)


Achso .. ich sollte evt. noch erwähnen das ich einen MySQL-UPDATE machen will.
Also "UPDATE table SET datum = formatiertes_datum"
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 23.10.11 17:32 
Moin!

user profile iconOliverN_26 hat folgendes geschrieben Zum zitierten Posting springen:
Ich habe folgens Datum: Fri Sep 16 2011 13:00:00 GMT+0200
Das soll so aussehen: 2011-09-16 13:00:00
Laut der Doku zu STR_TO_DATE() kann MySQL nix mit der Zeitzone hinten anfangen, sieht also schlecht aus. Wirst du also im Programm aufbereiten müssen. :nixweiss:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: So 23.10.11 22:30 
user profile iconOliverN_26 hat folgendes geschrieben Zum zitierten Posting springen:
"UPDATE table SET datum = formatiertes_datum"

Das sieht aber irgendwie nach unsauberem Datenbank-Design aus. In der Tabelle sollten doch die MySQL-Datumstypen (in dem Fall wohl DATETIME) verwendet werden, und keine formatierten Strings. Die Formatierung macht man eigentlich frühestens in der SELECT-Klausel (dort mit STR_TO_DATE), wenn nicht erst im Programm.

user profile iconOliverN_26 hat folgendes geschrieben Zum zitierten Posting springen:
Ich habe folgens Datum: Fri Sep 16 2011 13:00:00 GMT+0200

Das hast du im Programm, oder liegt es in der Datenbank?

Um mit Zeitzonen richtig umgehen zu können, muss man eigentlich nur einen Grundsatz beachten: Bei der Initialisierung der Datenkbank-Verbindung sollte die Zeitzone gesetzt werden, die auch verwendet wird. Das heißt, wenn man dort die lokale Zeitzone wählt, sollten die Daten auch in der lokalen Zeitzone eingefügt werden. Intern werden sie dann als UTC+00 gespeichert. Wenn du sie auslesen willst, musst du wiederum die Zeitzone richtig einstellen, und du bekommst sie in der gewünschten.
OliverN_26 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 252

Win7 64-Bit, WinXP SP3
Delphi 7 Enterprise
BeitragVerfasst: So 23.10.11 23:13 
Ich hab das Datum in einem Javascript und wandel es nun wie folgt um:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
T = D.start_date;
U = T.getYear();
V = T.getMonth()+1;
W = T.getDate();
X = T.getHours();
Y = T.getMinutes();
Z = T.getSeconds();
    
if (W < 10) W = "0" + W;
if (V < 10) V = "0" + V;
if (X < 10) X = "0" + X;
if (Y < 10) Y = "0" + Y;
if (Z < 10) Z = "0" + Z;
if (U < 1000) U+=1900;
  
var datum = U + '-' + V + '-' + W + ' ' + X + ':' + Y + ':' + Z;
alert(datum);

Läuft so. Gibts das noch schöner oder is das die "ultimative" Lösung?

Danke
baka0815
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 489
Erhaltene Danke: 14

Win 10, Win 8, Debian GNU/Linux
Delphi 10.1 Berlin, Java, C#
BeitragVerfasst: Mo 24.10.11 13:10 
Gibt es einen Grund warum du nicht mit Parametern arbeitest?
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Di 25.10.11 13:51 
user profile iconOliverN_26 hat folgendes geschrieben Zum zitierten Posting springen:
Läuft so. Gibts das noch schöner oder is das die "ultimative" Lösung?

Dafür gibt's die Funktion Date.format: :idea:

ausblenden Quelltext
1:
alert(D.start_date.format('yyyy-mm-dd HH:MM:ss'));					


Allerdings verstehe ich nicht, was das jetzt mit MySQL zu tun hat.